Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# undo file.ReadLine()

Tags:

c#

readline

I am reading huge textfile (1.8 GB) with

     while ((j = file.ReadLine()) != null) {...}

However, after some operations i got myself into situation, when I would like to 'undo' last ReadLine, so the next ReadLine would actually read exactly the same line.

Is there any way to do it? :)

The same job would do 'looking at next character' without any reading, so that I could, based on this character, decide if I want to read next line or not.

example:

    >1
    abc
    def
    >2
    ghi

After I read 'def' with ReadLine() I want to know if the next line contains '>' character or if there are just letters of alphabet.

Thanks a lot.

like image 915
Perlnika Avatar asked Apr 26 '26 19:04

Perlnika


2 Answers

For just 'looking at next character', use the Peek() method:

http://msdn.microsoft.com/en-us/library/system.io.streamreader.peek(v=VS.100).aspx

like image 104
Stefan Paul Noack Avatar answered Apr 29 '26 09:04

Stefan Paul Noack


For looking at the next character you can use the method Peek.

This will return the next character without changing your location in the file.

like image 23
Wouter de Kort Avatar answered Apr 29 '26 09:04

Wouter de Kort