Going through a text file line by line in vb 2005

冷暖自知 提交于 2020-02-06 05:51:25

问题


So my program needs to go through a plain text file line by line essentially:

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

etc until its done with the entire file does anyone know any good coding examples for this, all the tutorials seem to show open and writing/reading textfiles but nothing on how to do it line by line.


回答1:


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



回答2:


You could 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


来源:https://stackoverflow.com/questions/283156/going-through-a-text-file-line-by-line-in-vb-2005

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!