Check if StreamReader can read another line

I need to check if a string 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 clearly does not work, so how can I make this choice?

+4
source share
3 answers
+4
source
 String row; while((row=reader.ReadLine())!=null){ array[i]=row; } 

Must work.

+4
source

StreamReader.ReadLine reads a string of characters from the current stream, and the position of the reader in the Stream base object increases by the number that the method could read. So, if you call this method a second time, you will read the next line from the base stream. The solution is simple - save the string in a local variable.

 string line; while((line = reader.ReadLine()) != null) { array[i] = line; } 
+4
source

All Articles