System.StringComparer that supports wildcard (*)

后端 未结 3 362
梦如初夏
梦如初夏 2021-01-14 11:17

I\'m looking for a fast .NET class/library that has a StringComparer that supports wildcard (*) AND incase-sensitivity. Any Ideas?

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-14 11:42

    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 ))
    {
        ...
    }
    

    This would match prefix*suffix. You might also consider using StartsWith or EndsWith as alternatives.

提交回复
热议问题