支持通配符的System.StringComparer(*)

Alo*_*kin 3 .net c# stringcomparer

我正在寻找一个快速的.NET类/库,它具有支持通配符(*)AND incase-sensitivity的StringComparer.有任何想法吗?

tva*_*son 5

您可以将Regex与RegexOptions.IgnoreCase一起使用,然后与IsMatch方法进行比较.

var wordRegex = new Regex( "^" + prefix + ".*" + suffix + "$", RegexOptions.IgnoreCase );

if (wordRegex.IsMatch( testWord ))
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

这会匹配prefix*suffix.您也可以考虑使用StartsWith或EndsWith作为替代方案.