string.remove problem

evad4682

Well-known member
Joined
Nov 7, 2005
Messages
55
Programming Experience
Beginner
This seems very simple. I must be overlooking something easy. I am trying to remove a character from a string and I am failing miserably.

VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] status [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = "status in ('status1','status2','status3',)"[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] L [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[SIZE=2]L = status.Length[/SIZE]
[SIZE=2]L = L - 2[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] status.Substring(L) = ",)" [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'this reads from the comma forward[/COLOR][/SIZE]
[SIZE=2]status.Remove(L, 1)                  [/SIZE][SIZE=2][COLOR=#008000]'this deletes the commma (**i thought)[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2]MsgBox(status)[/SIZE]

The status.Remove line is not removing anything at all. Am I using the wrong stuff? What I want my status string to read is:
"status in ('status1','status2','status3')"

Thanks for the newbie help:D
 
String.Remove method is a function method, the result of the operation is returned from the function. You are not catching that return here.
 
I am not sure that I understand...
I don't know what you mean by a function method and returned from the function.
Is it possible to remove a character from a string?
I am still pretty new to this and I am attempting to teach myself.

Thanks for all the help.
 
In case anybody reads this post this is what I ended up doing

VB.NET:
If status.Substring(l) = ",)" Then
status = status.Remove(status.LastIndexOf(","), 1)
End If

Thanks again for the help
 
Last edited by a moderator:
Back
Top