Erm, I'm trying to think of a way to count the number of lines in a text file.
Well, I thought of
while( fgets()... == '\n') counter++;
am I right? BTW, does fgets exist in C#?
Any suggestions/corrections?
Printable View
Erm, I'm trying to think of a way to count the number of lines in a text file.
Well, I thought of
while( fgets()... == '\n') counter++;
am I right? BTW, does fgets exist in C#?
Any suggestions/corrections?
If the textfile aint too big and/or you don't care about a slight performance hit you could split each line:
Code:int NrOfLines = System.IO.File.ReadAllText("MyFile.txt").Split(new string[] { "\n" }, System.StringSplitOptions.None).Length;
Magos is the man!
Been wondering about the address of text streams and lines in files with regarding the \n character for some time myself. Very simple and to the point. Excellent!!
Thank you very much.