I would like to ask if there is any posibility to read previous lines (or chars) with StreamReader.
My problem is that I am reading pretty big file (even GBs) but sometimes I want to go back to previous (second) '#' (it should be usually in 10k chars far). So I wanted to seek somehow back. Hovewer, StreamReader.BaseStream.Seek() doesnt move a pointer anywhere and when I call Peek() again there is no change in reading.
Is there some way to do that?
My code:
int counterOfSharps = 0;
while(counterOfSharps < 2 && streamReader.BaseStream.Position > 0){
streamReader.BaseStream.Position = streamReader.BaseStream.Seek(-1, SeekOrigin.Current);
if (streamReader.Peek() >= 0 && Convert.ToChar(streamReader.Peek()) == '#')
counterOfSharps++;
}
So changing position by -1 to get previous char, but the only thing is changing is position, but Peeking is still getting former char.