0

Where do I find the exact and complete string comparison rules for a certain culture in C#?
Example: With StringComparer.InvariantCulture the strings "Masse" and "Maße" are equal.
There needs to be list of rules.

There have been similar questions, like:
Difference between InvariantCulture and Ordinal string comparison
This explains the concepts and gives examples. But I would like to have the source where the actual rules are defined.

cdoubleplusgood
  • 1,309
  • 1
  • 11
  • 12
  • 1
    "There needs to be list of rules." heh; no, not really - at least, not exhaustively; also: `StringComparer.InvariantCulture.Equals("Masse", "Maße")` returns `false` for me... do you mean sort compares, i.e. `Compare`? Because that returns `-1` for me; note: if it returned `0`, it wouldn't mean "they are equal" - it would mean "they should be sorted similarly" – Marc Gravell Jun 30 '22 at 13:20
  • Does this answer your question? [Difference between InvariantCulture and Ordinal string comparison](https://stackoverflow.com/questions/492799/difference-between-invariantculture-and-ordinal-string-comparison) – emagers Jun 30 '22 at 13:23
  • @MarcGravell Just tried again: bool b = StringComparer.InvariantCulture.Equals("Masse", "Maße"); is `true` in .Net Framework 4.8. – cdoubleplusgood Jun 30 '22 at 13:23
  • @emagers: Only partially, although it goes in the right direction. Still it only gives some examples. – cdoubleplusgood Jun 30 '22 at 13:26
  • 1
    This article explains differences between the "old" Framework and .NET 5+: [Behavior changes when comparing strings on .NET 5+](https://learn.microsoft.com/en-us/dotnet/standard/base-types/string-comparison-net-5-plus). – Olivier Jacot-Descombes Jun 30 '22 at 13:27
  • 1
    Maybe for deeper digging into this topic the MS documention for how things should be used [here](https://learn.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings) – Dominik Jun 30 '22 at 13:28
  • It uses ICU now, see https://icu.unicode.org/home for full details. – Matthew Watson Jun 30 '22 at 14:35

1 Answers1

0

For C#, this has historically varied depending on which version and flavor of C# and what OS you're running on.

Olivier's comment is an excellent current source of information: Behavior changes when comparing strings on .NET 5+.

I expect this unification of C# on all platforms based on ICU to be stable.

ICU is an API that is driven by data from the Unicode CLDR project. So the precise mappings and equivalences in your example are ultimately derived from CLDR.

Paul Dempsey
  • 639
  • 3
  • 19