Differences between StringComparison.InvariantCulture
and StringComparison.Ordinal
are fairly easy to find, since Ordinal means that the string is not normalized before it is compared. So we just have to combine an normalized string to an unnormalized string.
Finding differences between StringComparison.InvariantCulture
and StringComparison.CurrentCulture
(or differences between different CurrentCulture
s) is a bit more difficult, but they do exist.
Here is one example:
string a = "\u00C4"; // "LATIN CAPITAL LETTER A WITH DIAERESIS"
string b = "\u0041\u0308"; // "LATIN CAPITAL LETTER A" - "COMBINING DIAERESIS"
Console.WriteLine(a.Equals(b, StringComparison.InvariantCulture)); // true
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);
Console.WriteLine(a.Equals(b, StringComparison.CurrentCulture)); // true
Thread.CurrentThread.CurrentCulture = new CultureInfo("da-DK", false);
Console.WriteLine(a.Equals(b, StringComparison.CurrentCulture)); // false
Console.WriteLine(a.Equals(b, StringComparison.Ordinal)); // false
Or this one that only uses ASCII characters:
string ddzs = "ddzs";
string dzsdzs = "dzsdzs";
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);
Console.WriteLine(ddzs.Equals(dzsdzs, StringComparison.CurrentCulture)); // false
Thread.CurrentThread.CurrentCulture = new CultureInfo("hu-HU", false);
Console.WriteLine(ddzs.Equals(dzsdzs, StringComparison.CurrentCulture)); // true