Sunday, April 01, 2012 9:48 PM
I have a text label, split half-and-half with a "/".
This is an example:
label1.text = "I like dogs/I like cats"
This will not be the same text (and not the same text length) every times. I need to delete everything before the "/" with only a button. (for example, delete "I like dogs")
I already tried to make a SubString, and a indexOf, but it didn't work...
I realy need help,
Sunday, April 01, 2012 10:01 PMShow what you've already tried. :)
Sunday, April 01, 2012 10:10 PM
Dim myString As String = "I like dogs/I like cats" Dim newString As String newString = myString.Substring(myString.IndexOf("/") + 1)
Something like that.
Jordan St. Godard| Microsoft® Community Contributor 2011
Sunday, April 01, 2012 10:11 PM
I found this code in some forums, but they didn't work..
And the label1.text was:
Dim s As String = Label1.Text Dim i As Integer = s.IndexOf("/"c) Do While (i <> -1) Label2.Text = (s.Substring(i)) i = s.IndexOf("/"c, i + 1) Loop Label2.Text = i
and also try this:
Dim s As String = label1.text Dim i As Integer = s.IndexOf("/"c) Dim part As String = s.Substring(i) Label2.Text = partLabel2 should be the result. (I should get: "I like cats")
Sunday, April 01, 2012 10:15 PMYou're almost there. In the second version use i+1 instead of only i. As the index of the "/" is in i, the part after it is starts at i + 1.
Thursday, May 24, 2012 9:52 PM
Ok this is good! Thank you!
But now, if I want to only keep "I like dogs" and delete "/I like cats"
Is it possible?
Thursday, May 24, 2012 11:18 PM
sure, then use
Dim part As String = s.Substring(0, i) Label2.Text = part
- Marked As Answer by Chod3479 Friday, May 25, 2012 12:54 AM