如何检查是否两个字符串在C#中的部分匹配? [英] How to check if two string are a partial match in C#?

查看:700
本文介绍了如何检查是否两个字符串在C#中的部分匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:结果
是否有任何模糊搜索或字符串相似性为C#?






我创建这将只准歌曲或艺术家或专辑名称的用户输入,然后将搜索字符串数组或ArrayList的任何应用程序可能的匹配。



自动建议将根据匹配百分比来计算。



例如



如果用户键入链接PRK 它应该找到林肯公园链接80 链接·雷但匹配百分比将是所有



不同的

假设收集只会搜索在艺术家收集和宋歌收集名演出者的名字。



(百分比数字只是说明)


$ 98%
链接·雷-82%
链接80 - - 62%
 林肯公园/ pre> 

解不必是C#代码,任何正则表达式或伪代码将是很好的,但应该在C#实现的。


< DIV CLASS =h2_lin>解决方案

通常 Levenshtein距离的实现也称为编辑距离被用于此目的。这将发现的基础上,将一个字符串转换成另一个需要编辑的最小数量的匹配,计算所有的插入,删除或单个字符替换作为衡量的成本 - 候选人则具有最低的成本弦



下面对的文章在C#泛型实现。


Possible Duplicate:
Are there any Fuzzy Search or String Similarity Functions libraries written for C#?

I am creating an application which will except user input of a Song or Artist or Album name and then will look through a String Array or ArrayList for any possible matches.

The auto suggestions will be calculated based on the match percentage.

For example

If user types link prk it should find Linkin Park or Link 80 or Link Wray but the match percentage will be different for all

Assume that the collection will only search for Artist names in Artist Collection and Song name in song collection.

(Percentage figures are just for explanation)

Linkin Park - 98%
Link Wray -82%
Link 80 - 62%

Solution does not have to be C# code, any regex or pseudo code will be good but should be implementable in C#.

解决方案

Usually an implementation of the Levenshtein distance also called edit distance is used for this. This will find matches based on the minimum number of edits needed to transform one string into the other, counting all insertions, deletions, or substitutions of a single character as a measure for the "cost" - candidates are then strings that have the minimum cost.

Here's a link to an article with a generic implementation in C#.

这篇关于如何检查是否两个字符串在C#中的部分匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆