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?
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;
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
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.
Last edited by TheRaven; 04-30-2008 at 01:49 AM.