C # Java culture and inconsistency

Consider this comparison:

String a = "\u00C4";       // "LATIN CAPITAL LETTER A WITH DIAERESIS"
String b = "\u0041\u0308"; // "LATIN CAPITAL LETTER A" and "COMBINING DIAERESIS"

Comparing them in Danish C # culture, returns false:

Thread.CurrentThread.CurrentCulture = new CultureInfo("da-DK", false);
Console.WriteLine(a.Equals(b, StringComparison.CurrentCulture));   // false

Comparing them in Java Danish, returns true:

System.out.println(Collator.getInstance(new Locale("Danish (Denmark)").equals(a,b)); // true

I listed all the locales / cultures in both environments and confirmed that the correct ones were selected. Am I missing something? What's the difference?

+5
source share
1 answer

I cannot reproduce your results using .NET 4:

using System;
using System.Globalization;
using System.Threading;

public class Test
{
    static void Main()
    {
        String a = "\u00C4";
        String b = "\u0041\u0308";

        Thread.CurrentThread.CurrentCulture = new CultureInfo("da-DK", false);
        Console.WriteLine(a.Equals(b, StringComparison.CurrentCulture));
    }
}

This program prints "True" for me. Exactly the same program prints "False" for you?

+4
source

All Articles