C# 两个字符串数组的交集(忽略大小写)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10323071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 13:22:21 来源:igfitidea点击:
Intersection of two string array (ignore case)
提问by Ali
I have two arrays:
我有两个数组:
string[] array1 = { "Red", "blue", "green", "black" };
string[] array2 = { "BlUe", "yellow", "black" };
I need only the matching strings in one array (ignoring case).
我只需要一个数组中的匹配字符串(忽略大小写)。
Result should be:
结果应该是:
string[] result = { "blue", "black" } or { "BlUe", "black" };
采纳答案by user7116
How about an Enumerable.Intersectand StringComparercombo:
Enumerable.Intersect和StringComparer组合怎么样:
// other options include StringComparer.CurrentCultureIgnoreCase
// or StringComparer.InvariantCultureIgnoreCase
var results = array1.Intersect(array2, StringComparer.OrdinalIgnoreCase);

