I'm reading a text file through a streamreader. Does the streamreader have something like a "number of lines in file" property, or do I just have to loop until the eof? Thanks.
Printable View
I'm reading a text file through a streamreader. Does the streamreader have something like a "number of lines in file" property, or do I just have to loop until the eof? Thanks.
VB Code:
Debug.Print(ioReader.ReadToEnd.Split(CChar(Environment.NewLine)).GetUpperBound(0).ToString)
A StreamReader is a forward-only stream. This means it has no idea what data is available on the stream until it reads it, but once it has read it it cannot go back and read it again. Remix's code will give you the number of lines (or actually one less than the number of lines) but, as you see, it has to read the entire file to get that information. There is no way to, for instance, only read the file if it is greater than a certain length. You must read the whole file to determine that length.
Ok, thanks.