Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

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.

like image 270
Ivan Avatar asked Jul 11 '12 08:07

Ivan


1 Answers

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.

like image 70
Jeppe Stig Nielsen Avatar answered Sep 28 '22 07:09

Jeppe Stig Nielsen