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

前端 未结 5 738
夕颜
夕颜 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:05

    If you need to be able to jump to line 24,000 using a function that does ReadLine() in the background will be a bit slow.

    If the line number is high you may want to make some sort of educated guess as to where in the file the line may be and start reading from there. That way to get to line 24,567 you don't have to read 24,566 lines first. You can skip to somewhere in the middle find out what line you are on based on the number after the /t and then count from there.

    A while back I worked with a dev who had to build a DB before RDBMSs where common. His solution to your problem was similar to what I just wrote about but in his case he kept a map in a separate file. The map can map every hundredth line to its location in the document. A map like this can be loaded very quickly and this may increase read times. At the time his system was very fast and efficient for readonly data but not very good for read/write data. (every time you change the lines you have to change the whole map, this is not very efficient)

提交回复
热议问题