How do you search a large text file for a string without going line by line in C#?

后端 未结 14 1804
灰色年华
灰色年华 2020-12-15 08:23

I have a large text file that I need to search for a specific string. Is there a fast way to do this without reading line by line?

This method is extremely slow beca

相关标签:
14条回答
  • 2020-12-15 09:12

    Is your project needing to search different files for the same or different string every time, or searching the same file for different strings every time?

    If it's the latter, you could build an index of the file. But there's no point doing this if the file changes frequently, because building the index will be expensive.

    To index a file for full text searching, you could use the Lucene.NET library.

    http://incubator.apache.org/lucene.net/

    0 讨论(0)
  • 2020-12-15 09:13

    Given the size of the files would you really want to read them entirely into memory beforehand? Line by line is likely to be the best approach here.

    0 讨论(0)
提交回复
热议问题