2014-04-02 32 views
0

我有一个长度超过100000行的文本文件。当我尝试使用下面的代码无法解析用Linux生成的.Txt文件的每一行

Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(txtName) 

通过文件的所有行去,我算线我只看到我读90000行的文件。

我应该注意到,我确实从Linux机器上获得了这个文件。如果这有助于在所有 编辑:更完整的代码

For Each txtName As String In Directory.EnumerateFiles(mydocpath, "*.log") 
    Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(txtName) 
     MyReader.TextFieldType = FileIO.FieldType.Delimited 
      MyReader.SetDelimiters(" ") 
      Dim currentRow As String() 
      While Not MyReader.EndOfData 
       currentRow = MyReader.ReadFields() 
       Console.WriteLine(currentRow.Length) 
       LineCount +=1 
      End While 
    End Using 
Next 

我应该指出,总是忽略了同一行,当我移动这些线到另一个文件时,它可以读取它们就好了,但是当我观赏所有特殊在记事本++中的字符我找不到任何不寻常的东西,它无法读取的行或上面的行

+0

如果您的问题是关于读取文本文件的问题,您应该显示用于读取文本文件的代码。 – tinstaafl

+0

我认为你需要在“发生的事情”部分扩大一点。 –

+0

文本文件来自哪里?如果它来自Unix或Linux机器,则可能有其他问题,例如不同的行尾。 –

回答

0

不知道你在问什么,但似乎你想要得到文件中的行数if我是正确的......

Public Class Form1 

Private strFile As String = "LOCATION OF FILE" 


Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click 
    Dim wFile As StreamReader 
    wFile = New StreamReader(strFile, FileMode.Open) 
    Dim count As Integer = 0 'Counter for rows that have something in it 
    Dim totalLines As Integer = 0 'Counter for the total lines in the file 
    Dim blankLines As Integer = 0 'Counter for the empty lines (optional) 

    While (wFile.Peek <> -1) 
     If wFile.ReadLine() = String.Empty Then 
      blankLines += 1 ' Add to blank line count 
     Else 
      count += 1 'Add to actual count data from a line 
     End If 
     totalLines += 1 'The actual total of lines 
    End While 

    wFile.Close() 
End Sub 
End Class 

下面是一个文本文件,我看我的结果的截图...

Results from my run...

在另一方面,当该文件在记事本中加载++我得到同样的结果...

+0

是的,这个数字是关于让行数匹配一个他们不怎么样,谢谢你提交这个解决方案,虽然 – SZman

+0

我发现你的问题,提供的解决方案工作得很好......我实际上正在研究一个你发布的修复程序,但你想要一个行数,我把它给你... – Codexer

+0

这工作完美,但我仍然不知道如何我的代码正在跳过线 – SZman