开发者

C# Culture and Java Locale mismatch

开发者 https://www.devze.com 2023-02-09 13:06 出处:网络
Consider this comparison: String a = \"\\u00C4\";// \"LATIN CAPITAL LETTER A WITH DIAERESIS\" String b = \"\\u0041\\u0308\"; // \"LATIN CAPITAL LETTER A\" and \"COMBINING DIAERESIS\"

Consider this comparison:

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

Comparing these in C# Danish cultu开发者_Python百科re, returns false:

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

Comparing these in Java Danish locale, returns true:

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

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


I can't 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));
    }
}

That program prints "True" for me. Does the exact same program print "False" for you?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号