在Java中将希腊语转换为大写 [英] Converting Greek to Uppercase in Java
问题描述
我想做的事情很简单:
String example = "Τάχιστη αλώπηξ βαφής ψημένη γη - Mary Had A Little Lamb";
String upper = example.toUpperCase();
在希腊语中,只有大写单词的第一个字母应包含重音字符。
In Greek, only the first letter of an uppercase word should contain accented characters.
// upper contains the following (incorrect) string:
// ΤΆΧΙΣΤΗ ΑΛΏΠΗΞ ΒΑΦΉΣ ΨΗΜΈΝΗ ΓΗ - MARY HAD A LITTLE LAMB
// correct string:
// ΤΑΧΙΣΤΗ ΑΛΩΠΗΞ ΒΑΦΗΣ ΨΗΜΕΝΗ ΓΗ - MARY HAD A LITTLE LAMB
(重音很难看,但它们就在那里。)
(The accents are hard to see, but they're there.)
根据 Java 1.7文档,我应该可以通过区域设置为 toUpperCase
,如下所示:
According to the Java 1.7 documentation, I should be able to pass a locale to toUpperCase
, like so:
String upper = example.toUpperCase(new java.util.Locale("el"));
但是,看起来没有 toUpperCase的具体规则
正确处理希腊语。
However, it looks like there are no specific rules for toUpperCase
which handle Greek correctly.
是否可以为特定区域设置定义 toUpperCase
的行为,以便我可以确保获得正确的结果?
Is it possible to define the behavior of toUpperCase
for a particular locale, so that I can ensure I get the correct result?
或者,我可以编写一个实用程序类来处理这种特殊情况。但是如果可能的话,我宁愿在每个语言环境中覆盖此函数,以防其他语言出现。
Alternatively, I can just write a utility class to handle this particular case. But if it's possible, I'd prefer to override this function per locale, in case this comes up for other languages.
推荐答案
Per @ajb默认情况下不支持Java。我必须创建自己的解决方案。
Per @ajb, this is not supported in Java by default. I had to create my own solution.
这篇关于在Java中将希腊语转换为大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!