VBForums >
.NET >
C# > [2.0] How to get the number of lines in a text file?
Click to See Complete Forum and Search --> : [2.0] How to get the number of lines in a text file?
dekelc
Jun 19th, 2006, 06:47 PM
Hello!!
I have a text file with some lines in it.
How can I know the number of lines in that file?
thanks!
:wave:
penagate
Jun 19th, 2006, 06:52 PM
Read it in, count the number of \n characters, add one.
jmcilhinney
Jun 19th, 2006, 07:28 PM
You can't know the number of lines without reading them. The simplest way in .NET 2.0 is:IO.File.ReadAllLines().LengthIf you actually want to keep the data then you'd assign the result of ReadAllLines to a String() variable and then use the Length property of that.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.