小编use*_*467的帖子

c#搜索大文本文件

我正在尝试优化搜索大文本文件(300-600mb)中的字符串.使用我目前的方法,它需要太长时间.

目前我一直在使用IndexOf搜索字符串,但是花费的时间太长(20秒)来为每个字符串构建一个索引.

如何优化搜索速度?我试过Contains()但这也很慢.有什么建议?我正在考虑正则表达式匹配,但我没有看到有显着的速度提升.也许我的搜索逻辑是有缺陷的

while ((line = myStream.ReadLine()) != null)
{
    if (line.IndexOf(CompareString, StringComparison.OrdinalIgnoreCase) >= 0)
    {
        LineIndex.Add(CurrentPosition);
        LinesCounted += 1;
    }
}
Run Code Online (Sandbox Code Playgroud)

c# io search full-text-search

5
推荐指数
2
解决办法
8549
查看次数

标签 统计

c# ×1

full-text-search ×1

io ×1

search ×1