I need to check if a line contains a string before I read it, I want to do this using a while loop something like this
while(reader.ReadLine() != null)
{
array[i] = reader.ReadLine();
}
This obviously doesen't work, so how can I do this selection?
Try using the Peek
method:
while (reader.Peek() >= 0)
{
array[i] = reader.ReadLine();
}
Docs: http://msdn.microsoft.com/en-us/library/system.io.streamreader.readline.aspx and http://msdn.microsoft.com/en-us/library/system.io.streamreader.peek.aspx
String row;
while((row=reader.ReadLine())!=null){
array[i]=row;
}
Should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With