【发布时间】:2015-04-09 16:41:37
【问题描述】:
我有一个字符串,我想将它与字符串列表进行比较以找到最佳匹配。
例如,
string search = "Orange Black Red One Five"
字符串列表可以包含以下内容
l[0] = "Orange Seven Three Black"
l[1] = " Nine Eight Seven Six"
l[2] = " Black Blue Purple Red Five Four Nine Ten"
l[0] contains 2 matches
l[1] contains 0 matches
l[2] contains 3 matches
所以程序会选择 l[2] 作为最佳匹配,匹配率为 60%。
我将如何比较这样的两个字符串?
【问题讨论】:
-
将您的搜索字符串拆分为一个数组。然后在这里查看
Regex.Matches方法 - msdn.microsoft.com/en-us/library/b9712a7w(v=vs.110).aspx -
拆分
l[i],对于每个单词,循环search中的每个单词(作为一个数组)并计算匹配,存储最高的索引。
标签: c# .net string list compare