System.StringComparer that supports wildcard (*)

后端 未结 3 363
梦如初夏
梦如初夏 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:39

    alternatively you can try following

    class Wildcard : Regex
        {
            public Wildcard() { }
            public Wildcard(string pattern) : base(WildcardToRegex(pattern)) { }
            public Wildcard(string pattern, RegexOptions options) : base(WildcardToRegex(pattern), options) { }
            public static string WildcardToRegex(string pattern)
            {
                return "^" + Regex.Escape(pattern).
                Replace("\\*", ".*").
                Replace("\\?", ".") + "$";
            }
        }
    

提交回复
热议问题