Simple Loop question

aman_VB

Member
Joined
Apr 27, 2010
Messages
23
Programming Experience
1-3
I have a string with value ""123|abc|456|" separated by vertical bar. I want to create a sub that reads upto "|" and then exits the sub.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myString As String = "123|abc|456|"
For Each character In myString
If character <> "|" Then
TextBox1.Text += character
End If
Next
End Sub

My output looks like this 123abc456, which is not what I am looking for. How do you do this with Do While, and stop the loop when it encounters the vertical bar "|"? Many thanks.
 
VB.NET:
Private Const m_Pipe As String = "|"

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim myString As String = "123|abc|456|"
    If myString.Contains(m_Pipe) Then TextBox1.Text = myString.SubString(0I, myString.Indexof(m_Pipe))
End Sub
 
Back
Top