Ivan
Ivan

Reputation: 3184

String.Compare() with Hungarian CultureInfo works not correct for specific strings

String.Compare() with Hungarian CultureInfo works not correct for specific strings:

if (0 == String.Compare(@"ny", @"nY", true, new CultureInfo("hu-HU")))
  Console.WriteLine("Equal");
else
  Console.WriteLine("Not equal");

Of course I suppose to get "Equal" answer, but it's not. If I change the string it works properly (for example for "abc" and "ABC" it prints "Equal") It seems a problem with specific symbols.

Upvotes: 7

Views: 1088

Answers (1)

Jeppe Stig Nielsen
Jeppe Stig Nielsen

Reputation: 61952

What would you expect? In Hungarian, "ny" is considered one letter. It can be written like "ny", "Ny", or "NY". But never "nY". This works as expected:

  var hu = new CultureInfo("hu-HU");
  Console.WriteLine(String.Compare("Ny", "NY", true, hu));
  Console.WriteLine(String.Compare("ny", "NY", true, hu));
  Console.WriteLine(String.Compare("ny", "Ny", true, hu));

In Hungarian, they don't have a letter "y" except in foreign words and some names. But when you say "nY", there's no possibility that this could be the "ny" letter. So maybe .NET treats it as two letters.

Does anyone know Hungarian language well? It could be interesting to hear their opinion. But I'm pretty sure the string "nY" could never appear in "natural" Hungarian.

Upvotes: 5

Related Questions