i'm trying to change a number inside a string. (i.e. 5.39) if the
number in position 2 is < = 4 then change it to 4 if its > = 5
change it to a 9.
how would i do this in vb 2005?
I doubt you really want to do what you say. I'm not sure which
character you think is in position 2, so I assumed it is the '3'. You
probably don't want to assume that the decimal point is the second
character, use _str.IndexOf("."c) to find out where it is. You
probably also don't want the second Substring call in the last line
which keeps the digits beyond the one that is changed.
Dim _chr As String
Dim _index As Integer = 2
Dim _str As String = "5.39"
If _str.Substring(_index, 1).ToInt32 <= 4
_chr = "4"
Else
_chr = "9"
End If
_str = _str.Substring(0, _index) + _chr + _str.SubString(_index + 1)