2013-06-18 113 views
1

如何開始讀取我想要在某一行打開的文件?我需要打開的文件有一個標題,數據在第二行之前不會啓動,但我不知道如何將它放入代碼中,我從來沒有做過。在某些行讀取文件

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 

回答

4

如果你的文件有要放棄,然後開始分析後續的數據,你可以進入閱讀循環

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() 
之前使用 ReadLine方法
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