C# String.Contains忽略大小写

时间:2020-07-27 17:52:06   收藏:0   阅读:87

最近做一个代码生成器的时候 才发现。
C# 让String.Contains 默认是区分大小写的。

所以忽略的办法是:
方法一:
string title = "STRING"; bool contains = title.IndexOf("string", StringComparison.OrdinalIgnoreCase) >= 0;

方法二:封装起来

public static bool Contains(this string source, string toCheck, StringComparison comp) { return source.IndexOf(toCheck, comp) >= 0; }

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!