我正在寻找一个快速的.NET类/库具有支持通配符(*)和柜面灵敏度一个StringComparer。 任何想法?
I'm looking for a fast .NET class/library that has a StringComparer that supports wildcard (*) AND incase-sensitivity. Any Ideas?
您可以使用正则表达式与RegexOptions.IgnoreCase,然后用IsMatch方法进行比较。
You could use Regex with RegexOptions.IgnoreCase, then compare with the IsMatch method.
var wordRegex = new Regex( "^" + prefix + ".*" + suffix + "$", RegexOptions.IgnoreCase );
if (wordRegex.IsMatch( testWord ))
{
...
}
这将匹配 preFIX *后缀
。你也可以考虑使用StartsWith或的endsWith作为替代。
This would match prefix*suffix
. You might also consider using StartsWith or EndsWith as alternatives.