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:
|
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 SisodiyaPosted May 15, 2010, 1:05 AM
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
ScottPosted May 15, 2010, 4:44 AM
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: