CodeMonger CodeMonger - 12 days ago 7
Vb.net Question

vb.net Text File ReadLine

I have a text file I am trying to read and place into a datatable. The file looks like the below:

Control 1
- 1 Next line
- 1 Next Line
1 Same line

Control 2
- 2 Next line
- 2 Next Line
2 Same line


I want to structure the data like the below:

Title | Data
Control1, - 1 Next line - 1 Next line 1 Same line
Control2, - 2 Next line - 2 Next line 2 Same line


Do
Dim strInputFileLine As String = srReader.ReadLine()
If strInputFileLine Is Nothing Then Exit Do


If strInputFileLine.Contains("Control 1") Then
'How Do I get the Text before Control 2 Begins???


End If
loop

Answer

You can try this

Dim strInputFileLine As String
Dim nextLine,text As String
text = ""
        Do
            strInputFileLine  = srReader.ReadLine()
            If strInputFileLine Is Nothing Then Exit Do


            If strInputFileLine.Contains("Control 1") Then
                Do
                    nextLine = srReader.Readline()
                    If nextLine = "Control 2" Then Exit Do 'you can even use .Contains
                    Else
                        text += nextLine
                loop
            End If
       loop
Comments