You get the error because lines
is a string[]
not a single string
. But you want to stop on the first line that starts with "0"
anyway. So you could add the check in the foreach
:
foreach (string line in lines)
{
if(l.StartsWith("0")) break;
// ...
However, i would use this method instead to get only the relevant lines:
var lines = File.ReadLines(ofd.FileName).Skip(8).TakeWhile(l => !l.StartsWith("0"));
the difference is that ReadLines
does not need to process the whole file.