如何使IEnumerable的&LT;字符串&GT;。载不区分大小写? [英] How to make IEnumerable<string>.Contains case-insensitive?
问题描述
假如我有一个字符串数组.NET
Suppose I have a .net Array of strings.
string[] strings = new string[] { "AbC", "123", "Xyz", "321" };
如果我想看看,如果字符串数组包含ABC,我可以写
If I wanted to see if the array of strings contains "ABC", I could write
strings.Contains("ABC");
不过,假设我想要一个函数,将返回true,如果该字符串的大写值包含ABC。我可以大写整个数组,但它看起来像。载
方法有一些重载指定的比较,但我很困惑的语法。
However, suppose that I want a function that will return true if the uppercase values of the strings contain "ABC". I could uppercase the entire array, but it looks like the .Contains
method has some overloads for specifying the comparison, but I'm confused by the syntax.
我如何使用的IEnumerable&LT;字符串&GT;。载()
方法实现这个逻辑
How can I use the IEnumerable<string>.Contains()
method implement this logic?
推荐答案
使用重载 Enumerable.Contains 一>方法,它接受相等比较:
Use overloaded Enumerable.Contains method which accepts equality comparer:
strings.Contains("ABC", StringComparer.InvariantCultureIgnoreCase)
也有是在框中,您可以使用字符串比较器。
这篇关于如何使IEnumerable的&LT;字符串&GT;。载不区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!