String.Compare () with the Hungarian CultureInfo program does not work correctly for certain strings

String.Compare () with the Hungarian CultureInfo program does not work correctly for certain strings:

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

Of course, I should get the answer "Equal", but it is not. If I change the line, it works correctly (for example, for "abc" and "ABC" it prints "Equal"), It seems to be a problem with specific characters.

+7
source share
1 answer

What do you expect? In Hungarian, "ny" counts as one . It can be written as "ny", "Ny" or "NY". But never no. 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 do not have the letter "y", except for foreign words and some names. But when you say "nY" , there is no way that this could be the letter "ny". Therefore, it is possible that .NET treats it as two letters.

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

+4
source

All Articles