Read line by line, compare a value and extract prtion to display
I have a text file on c, i need to open and read the first line, verify if the 5 characters are = to some other text, if yes, display the REST of the text in the line, then repeat for each line on the file.txt until it reads all the lines in the text file. not sure how to do it...
My "code"
Dim fileReader As StreamReader fileReader = My.Computer.FileSystem.OpenTextFileReader("C:\locatin1/filetoshow.txt")
Dim stringReader As String
stringReader = fileReader.ReadLine()
[UpDate]
thanks for the help I took your advise and this is how it looks
'Each type of Message sent
Dim type1 As String = "d1err./"
Dim type2 As String = "d1jam./"
Dim type3 As String = "d1spe./"
Dim type4 As String = "d2err./"
Dim type5 As String = "d2jam./"
Dim type6 As String = "d2spe./"
Dim fileReader As StreamReader = My.Computer.FileSystem.OpenTextFileReader("C:\\locatin1\\filetoshow.txt")
Dim stringReader As String = fileReader.ReadLine()
While stringReader <> Nothing
Dim LineStart As String = stringReader.Substring(0, 7)
Dim RestOfLine As String = stringReader.Substring(7)
If LineStart = type1 Then
Display1.Dis1RTB1.Clear()
Display1.Dis1RTB1.Text = RestOfLine
ElseIf LineStart = type2 Then
Display1.Dis1RTB2.Clear()
Display1.Dis1RTB2.Text = RestOfLine
ElseIf LineStart = type3 Then
Display1.Dis1RTB3.Clear()
Display1.Dis1RTB3.Text = RestOfLine
ElseIf LineStart = type4 Then
Display2.Dis2RTB1.Clear()
Display2.Dis2RTB1.Text = RestOfLine
ElseIf LineStart = type5 Then
Display2.Dis2RTB2.Clear()
Display2.Dis2RTB2.Text = RestOfLine
ElseIf LineStart = type6 Then
Display2.Dis2RTB3.Clear()
Display2.Dis2RTB3.Text = RestOfLine
End If
stringReader = fileReader.ReadLine()
End While
fileReader.Close()
Last 2 questions
1. will this read each line and apply the rules for each line?
example of the text file i open and read below:
<line1> d1err./ error on machine
<line2> d1jam./ jam on machine
<line3>d1spe./
<line4>d2err./
<line5>d2jam./ jam on machine
<line6>d2spe./ machine needs maintenance
much appreciated