2

I am reading the CLR VIA C# by Jeffrey Richter. And while explaining string comparison, he notes that:

When the Compare method is not performing an ordinal comparison, it performs character expansions. A character expansion is when a character is expanded to multiple characters regardless of culture.

String s1 = "Strasse";
String s2 = "Straße";
Boolean eq;

CultureInfo ci = new CultureInfo("de-­DE");
eq = String.Compare(s1, s2, true, ci) == 0; // returns true

For the above case, he notes:

...the German Eszet character ‘ß’ is always expanded to ‘ss. So in the code example, the call to Compare will always return 0 regardless of which culture I actually pass in to it.

I want to know from which source, the runtime takes that ß is equal to ss or how it calculates it?

Farhad Jabiyev
  • 26,014
  • 8
  • 72
  • 98
  • 3
    The [reference source](https://referencesource.microsoft.com/#mscorlib/system/globalization/compareinfo.cs,1356715f78447ed6,references) leads to unmanaged code, `COMNlsInfo::InternalCompareString` so it's a dead end – Camilo Terevinto Jan 19 '19 at 19:54
  • Take a look at [This](http://www.unicode.org/charts/PDF/U0080.pdf) – NaDeR Star Jan 19 '19 at 20:07
  • 1
    Read the first line [here](https://stackoverflow.com/a/53138834/7444103). Or maybe follow the link. – Jimi Jan 19 '19 at 20:27
  • [A DIN standard?](https://www.unicode.org/reports/tr10/tr10-43.html#Special_Cases) – JosefZ Jan 13 '21 at 21:51

0 Answers0