我正在尋找一種簡單的方法來辨別如果一個字符串包含另一個字符串的任何部分(是正則表達式,內置函數,我不知道,等等。 ..)。例如:字符串不能包含另一個字符串的任何部分.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