Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List 'Except' comparison - ignore case

I have two lists and I want to compare them and get the differences, while ignoring any case differences.

I have used the following code to get the differences between the two lists but it does not ignore case differences.

IEnumerable<string> diff = list1.Except(list2);
List<string> differenceList = diff.ToList<string>();

I tried this:

IEnumerable<string> diff = list1.Except(list2, StringComparison.OrdinalIgnoreCase);

but Except does not seem to be having a string case check of that sort (so error). I'm hoping there's a work around.

like image 334
john Avatar asked Sep 05 '14 06:09

john


2 Answers

Try this :)

List<string> except = list1.Except(list2, StringComparer.OrdinalIgnoreCase).ToList();

Worked for me!

like image 124
Damitha Shyamantha Avatar answered Nov 02 '22 10:11

Damitha Shyamantha


Here's what worked:

IEnumerable<string> differenceQuery = inputTable.Except(strArrList,
                                                        StringComparer.OrdinalIgnoreCase);

Used StringComparer instead of StringComparison.

like image 42
john Avatar answered Nov 02 '22 09:11

john