我正在寻找一种简单的方法来辨别如果一个字符串包含另一个字符串的任何部分(是正则表达式,内置函数,我不知道,等等。 ..)。例如:字符串不能包含另一个字符串的任何部分.NET 2.0
string a = "unicorn";
string b = "cornholio";
string c = "ornament";
string d = "elephant";
if (a <comparison> b)
{
// match found ("corn" from 'unicorn' matched "corn" from 'cornholio')
}
if (a <comparison> c)
{
// match found ("orn" from 'unicorn' matched "orn" from 'ornament')
}
if (a <comparison> d)
{
// this will not match
}
像if (a.ContainsAnyPartOf(b))
这样的东西将是太多的希望。
另外,我只能访问.NET 2.0。
提前致谢!
来自独角兽的“o”与cornholio中的“o”匹配吗? – 2010-04-21 13:14:55
所以'a'和'd'不匹配,即使它们都包含子字符串'“n”'? – 2010-04-21 13:15:00