Question

I have a text file that is over 100000 lines long. When I try to go through all the lines of the file using the following code

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

and I count the lines I only see that I read 90000 lines of the file.

I should note that I did get this file off of a Linux machine. If that helps at all edit: more complete code

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

I should mention that is always misses the same line and when I move those lines to another file it can read them just fine, however when I view all special characters in Notepad ++ I cannot find anything out of the ordinary with the line it cannot read or the lines above them

Était-ce utile?

La solution

Not sure what you are asking, but it seems you want to get a count of lines in the file if I am correct...

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

Here's a screenshot of my results from a text file I read...

Results from my run...

On another note, when this file is loaded in Notepad++ I get the same results...

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top