Hi, in C++ when I want to loop text in from a text file I use eof
ie.
while (!List.eof())
{
getline (List,line);
_str1 = line;
getline (List,line);
_str2 = line;
}
In C# there isnt a eof which I know of. Any ideas?
Thanks.
Printable View
Hi, in C++ when I want to loop text in from a text file I use eof
ie.
while (!List.eof())
{
getline (List,line);
_str1 = line;
getline (List,line);
_str2 = line;
}
In C# there isnt a eof which I know of. Any ideas?
Thanks.
Peek will return -1 when there is nothing else to read.Code:using (TextReader tr = new StreamReader(@"C:\test\test.txt"))
{
while (tr.Peek() >= 0)
{
// read the line and do whatever with it
}
}
Code:using (StreamReader SR = new StreamReader("C:/myfile.txt")) {
string line = null;
while ((line = SR.ReadLine()) != null) {
//do something with the line
}
}
Thanks, that isn't quite what would work with what I wanted, as I have data which I want to be collected in lines of 5, and then cycled again to get the next 5 etc etc.. This seems to give me a line and do something with it, and then a separate single other line. (I think). However, great piece of code for the future, Thank you!
This worked perfectly for what I needed.
Thank you.
Thanks Both :)