Wednesday, October 12, 2011

Count Lines in File


The fastest solution + holds only 1 line at a time in the memory (best solution)

Private Function TotalLines(filePath As String) As Integer
 Using r As New StreamReader(filePath)
  Dim i As Integer = 0
  While r.ReadLine() IsNot Nothing
   i += 1
  End While
  Return i
 End Using
End Function

No comments:

Post a Comment