通过忽略某些字符来比较两个字符串 [英] Compare two strings by ignoring certain characters
问题描述
我想知道是否有一种简单的方法来通过排除字符串中的某些字符来检查两个字符串是否匹配.参见下面的示例.
I wonder if there is an easy way to check if two strings match by excluding certain characters in the strings. See example below.
我可以通过编写正则表达式来查找通配符"字符并将其替换为通用字符来轻松编写这种方法.然后比较两个字符串str1和str2.我不是在寻找这样的实现,而是想知道是否有任何.Net框架类可以解决此问题.似乎很常见,但是我找不到任何这样的方法.
I can easily write such a method by writing a regular expression to find the "wild card" characters, and replace them with a common character. Then compare the two strings str1 and str2. I am not looking for such implementations, but like to know whether there are any .Net framework classes that can take care of this. Seems like a common need, but I couldn't find any such method.
例如:
string str1 = "ABC-EFG";
string str2 = "ABC*EFG";
两个字符串必须声明为相等.
The two strings must be declared equal.
谢谢!
推荐答案
很抱歉,我认为正则表达式或用通用字符替换通配符"都是您最好的解决方案.基本上,您说过不想收到的答案.
Sorry but I think either regex, or replacing the "wildcard" characters with a common character are going to be your best solution. Basically, the answers that you stated you didn't want to receive.
这篇关于通过忽略某些字符来比较两个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!