C#比较类似的字符串 [英] C# comparing similar strings

查看:152
本文介绍了C#比较类似的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些通用的一些文件名(LIST1)和另一个biggeneric与完整的名称列表(LIST2)。
我需要将LIST1中的名称与LIST2中的类似名称进行匹配。例如

I have a generic with some filenames (LIST1) and another biggeneric with a full list of names (LIST2). I need to match names from LIST1 to similar ones in LIST2. For example

LIST1
- **MAIZE_SLIP_QUANTITY_3_9.1.aif**

LIST 2
1- TUTORIAL_FAILURE_CLINCH_4.1.aif
2- **MAIZE_SLIP_QUANTITY_3_5.1.aif**
3- **MAIZE_SLIP_QUANTITY_3_9.2.aif**
4- TUTORIAL_FAILURE_CLINCH_5.1.aif
5- TUTORIAL_FAILURE_CLINCH_6.1.aif
6- TUTORIAL_FAILURE_CLINCH_7.1.aif
7- TUTORIAL_FAILURE_CLINCH_8.1.aif
8- TUTORIAL_FAILURE_CLINCH_9.1.aif
9- TUTORIAL_FAILURE_PUSH_4.1.aif

我已阅读过 Levenshtein distance ,并在框架中使用它的实现( SignumFramework Utilities )。
它在第2行和第3行返回distance = 1。但是在我的例子中,第3行比第2行更匹配。

I've read about Levenshtein distance and used an implementation of it in a Framework (SignumFramework Utilities). It returns me distance=1 in lines 2 and 3. But in my case line 3 is a better match than line 2.

有没有另一种方法更好地比较类似的字符串?

Is there another method better to compare similar strings? Something more flexible?

推荐答案

当比较为字符串时,9.2不是比5.1 。如果您希望版本号以数字方式计算,您必须解析字符串,以便您可以分别比较字符串部分和数字部分。

When comparing as strings, "9.2" is not a better match than "5.1" for "9.1". If you want the version numbers to be evaluated numerically, you have to parse the strings so that you can compare the string parts and the numerical parts separately.

这篇关于C#比较类似的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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