相当于Java不变文化 [英] Java equivalent of Invariant Culture

查看:129
本文介绍了相当于Java不变文化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我转换下面的C#代码到Java。 ?是否有一个Java等同于固定区域性的.NET概念

 串上= myString.ToUpperInvariant(); 



由于固定区域性其实只是美国的文化,我可以做这样的事情在Java中,但我不知道是否有更好的方式:

 字符串上= myString.toUpperCase(Locale.US); 


解决方案

没有,那是基本上正确的道路要走。虽然的美国文化和格式方面的不变的文化差异,我不相信它们会影响大小写规则。



编辑:其实,一个快速的测试程序显示有的字符,这是在美国文化中的.NET不变区域性大写的区别为:

 使用系统; 
使用System.Globalization;

类测试
{
静态无效的主要()
{
的CultureInfo我们=新的CultureInfo(EN-US);
的for(int i = 0; I< 65536;我++)
{
字符C =(char)的我;
字符串s = c.ToString();
如果(s.ToUpperInvariant()= s.ToUpper(我们)!)
{
Console.WriteLine(i.ToString(×4));
}
}
}
}

输出

  00b5 
0131
拉丁文扩展-A
01c5
01c8
01cb
01f2
0345
0390
03b0
03C2
03d0
03d1
03d5
03d6
03f0
03f1
03f5
1e9b
1fbe

我没有时间在这些权利现在看起来,但它是值得探讨。我不知道,如果同样的差异会在Java中使用 - 你可能想利用这些样本,并制定出你希望你的代码做什么



编辑:而只是为了完美主义,这是值得一提的是单个字符......只有支票,而你真的上层套管整个字符串,它可以有所作为



综观的的Java 的对上层套管,这似乎只对TR,AZ和LT国家的具体语言环境的行为的代码。我知道,TR是土耳其,但我不知道其他人...


I am converting the following C# code to Java. Is there a Java equivalent to the .NET concept of Invariant Culture?

string upper = myString.ToUpperInvariant();

Since the Invariant Culture is really just the US culture, I could just do something like this in Java, but I'm wondering if there is a better way:

String upper = myString.toUpperCase(Locale.US);

解决方案

No, that's basically the right way to go. While there are differences between the US culture and the invariant culture in terms of formatting, I don't believe they affect casing rules.

EDIT: Actually, a quick test program shows there are characters which are upper-cased differently in .NET in the US culture to in the invariant culture:

using System;
using System.Globalization;

class Test
{
    static void Main()
    {
        CultureInfo us = new CultureInfo("en-US");
        for (int i = 0; i < 65536; i++)
        {
            char c = (char) i;
            string s = c.ToString();
            if (s.ToUpperInvariant() != s.ToUpper(us))
            {
                Console.WriteLine(i.ToString("x4"));
            }
        }
    }    
}

Output:

00b5
0131
017f
01c5
01c8
01cb
01f2
0345
0390
03b0
03c2
03d0
03d1
03d5
03d6
03f0
03f1
03f5
1e9b
1fbe

I don't have time to look at these right now, but it's worth investigating. I don't know if the same differences would apply in Java - you probably want to take a sample of them and work out what you want your code to do.

EDIT: And just to be completist, it's worth mentioning that that only checks for individual characters... whereas you're really upper-casing whole strings, which can make a difference.

Looking at the Java code for upper-casing, that appears to only have locale-specific behaviour for tr, az and lt countries. I know that tr is Turkey, but I don't know about the others...

这篇关于相当于Java不变文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆