Aim:
Read the text from a multi-line textbox line by line to remove all but an 8 character ID.
For example:
" Test ID: 12345678"
" Test ID: 12345678"
I wish to retrieve the ID's only and show on 1 line with a delimiter,
For example:
"12345678, 12345678"
I can do this on a single line using the following:
VB.NET Code VB.NET |
I've tried to replicate this on a multi-line using Splits, Substrings and a For...Each loop - but have just ended up with a headache..
Any help would be greatly appreciated!

Hirendra SisodiyaRank #258 · 9.8K reputationPosted May 14, 2010, 9:05 PM EDT
hello Scott
Suppose multiline textbox(TextBox1) has :
" Test ID: 12345678"
" Test ID: 12345678"
then you can try this code sample:
Dim ReadFromTextbox As String = TextBox1.Text
Dim ReadFromTextbox_LineByLine() As String = ReadFromTextbox.Split(Environment.NewLine)
Dim TempLineString As String = ""
Dim FinalString As String = ""
For i As Integer = 0 To ReadFromTextbox_LineByLine.Length - 1
TempLineString = ReadFromTextbox_LineByLine(i).Trim()
Dim Divide_TempLineString() As String = TempLineString.Split(":")
If Divide_TempLineString.Length > 0 Then
FinalString = FinalString & "," & Divide_TempLineString(Divide_TempLineString.Length - 1)
End If
Next
FinalString = FinalString.Trim()
If FinalString.StartsWith(",") Then
FinalString = FinalString.Remove(0, 1)
End If
thanks
Please mark as answere if it helps
Scott3 reputationPosted May 15, 2010, 12:44 AM EDT
For future readers, here's what i ended up doing:
Streamreading a text file into a string. Test file containing data such as:
" Test ID: 12345678.tif"
" Test ID: 12345678.tif"
Final solution:
Private Sub btnTrim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTrim.Click'define multi-lined string and split it Dim ReadFromString As String = sTemp Dim ReadFromString_LineByLine() As String = ReadFromString.Split(Environment.NewLine)'ensure no null values on runtime Dim TempLineString As String = "" Dim FinalString As String = ""