How to start reading file after designated number of lines
I've got the following text files. The task is simple: ignore the ALL the
lines in blue and START READING the file at the place indicated by the
arrow. (I posted a question similar but people's replies weren't working
so i decided to combine the answers and ask properly this time)
here is my code:
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
StreamReader sr = new StreamReader(File.OpenRead(ofd.FileName));
int i = 1;
while (!sr.EndOfStream)
{
if (i > 8)
textBox1.Text = sr.ReadLine(); // As soon as i get to
the arrow (8th line, I want to display the
line in the textbox in my application.)
sr.ReadLine();
i++;
}
}
}
}
My Problem: I dont think my while loop is right at all. When I try to
display what the while loop contains, nothing pops up in the textbox.
Secondly, THIS is the output I get with the code above:
It's clearly wrong, I dont even know where 0 subtotals and 671etc come from.
WHAT I expect the output to be is the first arrowed line: "1 MANDT CLIENT
etc etc "
Thanks guys
No comments:
Post a Comment