C#Culture和Java Locale不匹配

时间:2011-02-10 12:21:53

标签: c# java locale culture

考虑这种比较:

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

在C#丹麦文化中比较这些,返回false:

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

在Java Danish语言环境中比较这些,返回true:

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

我列出了两种环境中的所有语言环境/文化,并确认选择了正确的语言环境/文化。我错过了什么吗?有什么区别?

1 个答案:

答案 0 :(得分:4)

我无法使用.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));
    }
}

该程序为我打印“True”。完全相同的程序是否为您打印“False”?