[2008] read every line in a text file seperatly
Hi everyone,
How would i go about reading a text file from beginning to end but reading it as lines and not one huge string. For example if the text file contained 2 lines and the strings on each line were "line1" and "line2" ,respectively, how would i go about reading line1 then reacting to the value of line1 then reading line2 then reacting to it and so on. i think i could get it working if there were going to only two lines and i know what the values are but i don't. the actual values can be anything and the length in lines can be 30 (for now). any help would be great because i have been stuck on tis fro an hour. So thanks to all who can help.
Re: [2008] read every line in a text file seperatly
vb.net Code:
'declared at class level
Dim myfile = My.Computer.FileSystem.OpenTextFieldParser("C:\test.txt")
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' when button1 is clicked we output the next line from our file in a message box
Messagebox.Show(myfile.ReadLine())
End Sub
Obviously you dont have to show it in a messagebox and you dont have to have the readline() code in a button event handler but hopefully you get the idea.
Re: [2008] read every line in a text file seperatly
thanks that helped. i was over complicating it. was try to do loops and if thens and stuff but this worked fine.
Re: [2008] read every line in a text file seperatly
No problem. There's other ways you can do it but thats probably the simplest.