Moving the file cursor up lines?

后端 未结 3 578
囚心锁ツ
囚心锁ツ 2021-01-21 01:01

I\'ve googled this like crazy, and I can\'t seem to find any reference at all to this particular type of problem.

I have a StreamReader object with a file,

3条回答
  •  难免孤独
    2021-01-21 01:25

    Stream.Seek() (MSDN docs) is what you need, but that's an absolute position in the file, and has no notion of line breaks.

    I'd prefer to read the lines into a collection memory, then iterate over the collection in memory as often as you like before loading the next few lines in. In fact, unless you're talking gigglebytes of data, just read all the lines in as string objects in a List and do whatever you need with it.

提交回复
热议问题