Is there an option “go to line” in TextReader/StreamReader?

前端 未结 5 788
夕颜
夕颜 2021-01-18 01:16

I have a huge text file with 25k lines.Inside that text file each line starts with \"1 \\t (linenumber)\"

Example:

1   1   ITEM_ETC_GOLD_01    골드(소)          


        
5条回答
  •  长发绾君心
    2021-01-18 02:01

    You can use my LineReader class (either the one in MiscUtil or a simple version here) to implement IEnumerable and then use LINQ:

    string line5 = new LineReader(file).Skip(4).First();
    

    This assumes .NET 3.5, admittedly. Otherwise, open a TextReader (e.g. with File.OpenText) and just call ReadLine() four times to skip the lines you don't want, and then once more to read the fifth line.

    There's no way of "shortcutting" this unless you know exactly how many bytes are in each line.

提交回复
热议问题