65.9K
CodeProject is changing. Read more.
Home

Counting lines in a string

starIconstarIconstarIconstarIconstarIcon

5.00/5 (2 votes)

Jan 17, 2012

CPOL
viewsIcon

10331

Again, going with other people's comments about memory, how about using a Streamreader? (I haven't tested the timings (or code) but from memory..This should be fast (and memory efficient)...at least in my experience.StreamReader sr = new StreamReader("Put file here");Int32 cnt =...

Again, going with other people's comments about memory, how about using a Streamreader? (I haven't tested the timings (or code) but from memory..

This should be fast (and memory efficient)...at least in my experience.

StreamReader sr = new StreamReader("Put file here");
Int32 cnt = 0;

while (sr.ReadLine() != null)
{
    cnt++;
}