I have a large set of strings, including many duplicates. It is important that all of the duplicates have the same casing. So this set would fail the test:
String[] strings = new String[] { "a", "A", "b", "C", "b" };
....but this test would pass:
String[] strings = new String[] { "A", "A", "b", "C", "b" };
As I iterate through each string in strings, how can my program see that A is a case-insensitive duplicate of a (and thus fail), but allow the duplicate b through?
One simple approach would be to create two sets - one using a case-insensitive string comparer, and one using a case-sensitive one. (It's not clear to me whether you want a culture-sensitive string or not, or in which culture.)
After construction, if the two sets has a different size (
Count) then there must be some elements which are equal by case-insensitive comparison, but not equal by case-sensitive comparison.So something like: