C# - 两个大字符串数组的模糊比较

标签 c# string linq loops compare

我需要在 B 中找到“部分”存在于 A 中的所有字符串。

B = [ "Hello World!", "Hello Stack Overflow!", "Foo Bar!", "Food is nice...", "Hej" ]
A = [ "World", "Foo" ]
C = B.FuzzyCompare(A) // C = [ "Hello World!", "Foo Bar!", "Food is nice..." ]

我一直在研究使用 Levenshtein Distance Algorithm对于问题的“模糊”部分,以及 LINQ对于迭代。 但是,A * B 通常会导致超过 15 亿次比较。

我该怎么办?有没有办法快速“几乎比较”两个字符串列表?

最佳答案

也许简单地比较子字符串就足够了,这样效率会高得多:

var C = B.Where(s1 => A.Any(s2 => s1.IndexOf(s2, StringComparison.OrdinalIgnoreCase) >= 0)).ToList();

关于C# - 两个大字符串数组的模糊比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38332395/

相关文章:

c# - 需要带有 DateTime 转换的 lambda 表达式 OrderBy

c# - 如何将 Visual Studio Text Visualizer 用于自定义类型?

c# - 在泛型类中注释构造函数的正确方法是什么?

c# - 使用具有不同名称的系统类?

c++ - 如何显示文本中n个字母的单词数? C++

c# - ef 代码首先 : get entity table name without dataannotations

c# - 水平滚动条消失设置最后一列大小以填充

string - 是否可以在 C++/CLI 中获得指向 String^ 内部数组的指针?

.net - C#在字符串中添加一个字符

c# - LINQ 中 Sum 和 Aggregate 的区别