Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to manage backspace/backline

8 views
Skip to first unread message

Ernst Sauer

unread,
Sep 6, 2012, 5:07:20 AM9/6/12
to
Hello,

I want (for example) to read a certain line again,
so I thought this should work:

StreamReader sr;
sr = new StreamReader(rfile)
string line;
long pos;
int i=0;

while (i++<3)
{ if (i==2) pos=sr.BaseStream.Position;
line=sr.ReadLine();
sr.DiscardBufferedData(); // no success with and witout
}
sr.BaseStream.Seek(pos, SeekOrigin.Begin);


I have a small test-file.
With the first ReadLine() sr reads the whole file
(later he splits the lines)
and sets the pos to the end of the stream.
With sr.DiscardBufferedData() I can't even read the second line.

Of course I can write my own method, but is this really necessary?

Thanks
E.S.
0 new messages