Mark..... wrote:
Can someone tell me the easiest way to count the number of lines in a
text file?
I can write a loop to do this but it seems cumbersome.... there must
be an easier way??
Hi Mark. A loop is probably the best way to do this, and is really simple.
Because lines are of unpredictable length, without any kind of metadata
stored with the file it's impossible to determine its line count without
reading every byte. If you want to do it in the least possible code, you
could use an expression like this, at the expense of a great deal of
additional memory for large files:
new StreamReader("file.txt").ReadToEnd().Split(new char[] {'\n'}).Length
--
Derrick Coetzee, MCAD, MSFT (Speech Server)
This posting is provided "AS IS" with no warranties, and confers no
rights. Use of included code samples are subject to the terms
specified at
http://www.microsoft.com/info/cpyright.htm