My Form have a multiline textbox. In this textbox, theres lines like that:
name1 - phone1
and i have to convert every line in 2 variables (or array). eg:
name = "name1"
phone = "phone1"
how could i make it?
My Form have a multiline textbox. In this textbox, theres lines like that:
name1 - phone1
and i have to convert every line in 2 variables (or array). eg:
name = "name1"
phone = "phone1"
how could i make it?
Use Split method of string object.
Dim name() As String = TextBox1.Text.Split(New String() {vbCrLf}, StringSplitOptions.RemoveEmptyEntries)
Dim phone() As String = TextBox2.Text.Split(New String() {vbCrLf}, StringSplitOptions.RemoveEmptyEntries)
See if this helps.
For Each line As String In TextBox1.Lines '// loop thru all lines in TextBox.
If Not line = "" And line.Contains("-") Then '.. check if line is not empty and it .Contains "-".
With line.Split("-") '// shorten code a little by using the "With" statement.
MsgBox("Name: " & .GetValue(0) & vbNewLine & "Phone: " & .GetValue(1)) '// Display result.
'// line.Split("-").GetValue(0) will .Split the line and return the first item in the array.
End With
End If
Next
See if this helps.
For Each line As String In TextBox1.Lines '// loop thru all lines in TextBox. If Not line = "" And line.Contains("-") Then '.. check if line is not empty and it .Contains "-". With line.Split("-") '// shorten code a little by using the "With" statement. MsgBox("Name: " & .GetValue(0) & vbNewLine & "Phone: " & .GetValue(1)) '// Display result. '// line.Split("-").GetValue(0) will .Split the line and return the first item in the array. End With End If Next
thank you!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.