如何开始阅读我想在某一行打开的文件?我需要打开的文件有一个标题,数据直到第二行才开始,但我不知道如何将它放入代码中,我以前从未这样做过。
dt.Columns.Add("Mouse Command")
dt.Columns.Add("Mouse Position")
Dim delimiter As String = ","
Using parser As New TextFieldParser(file)
parser.SetDelimiters(delimiter)
While Not parser.EndOfData
' Read in the fields for the current line
fields = parser.ReadFields()
r = dt.NewRow
答案 0 :(得分:4)
如果您的文件有第一行要丢弃,然后开始解析后续数据,则可以在进入阅读循环之前使用ReadLine方法
Dim delimiter As String = ","
Using parser As New TextFieldParser(file)
parser.SetDelimiters(delimiter)
parser.ReadLine()
While Not parser.EndOfData
' Read in the fields for the current line
fields = parser.ReadFields()
答案 1 :(得分:0)
您可以先读取所有行,然后使用此处开始处理它们:
Dim lines() As String = IO.File.ReadAllLines(file)
For i As Integer = 2 To lines.Length - 1
' Read in the fields for the current line
'...
Next