Passing a text file line by line in vb 2005

Thus, my program should go through a simple text file line by line:

Read line 1:
Do commands
loop
Read line2:
Do Commands
loop

      

etc. until it is executed with the entire file, does anyone know of any good coding examples for this, all tutorials seem to open and write / read text files, but do nothing like doing this line by line.

+1


source to share


2 answers


For Each line As String In System.IO.File.ReadAllLines("file.txt")
  ' Do Something'
Next

      



+6


source


You can do it like this:



Using f As System.IO.FileStream = System.IO.File.OpenRead("somefile.txt")
    Using s As System.IO.StreamReader = New System.IO.StreamReader(f)
        While Not s.EndOfStream
            Dim line As String = s.ReadLine

            'put you line processing code here

        End While
    End Using
End Using

      

0


source







All Articles