System.StringComparer支持通配符(*) [英] System.StringComparer that supports wildcard (*)

查看:151
本文介绍了System.StringComparer支持通配符(*)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个快速的.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.

这篇关于System.StringComparer支持通配符(*)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆