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" };
How about an Enumerable.Intersect
and StringComparer
combo:
// other options include StringComparer.CurrentCultureIgnoreCase // or StringComparer.InvariantCultureIgnoreCase var results = array1.Intersect(array2, StringComparer.OrdinalIgnoreCase);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With