问题描述
我希望代码能够将字符串中的所有字符转换为Java中的大写或小写。
I wanted code to convert all the characters in strings to uppercase or lowercase in Java.
我发现了一个类似这样的方法:
I found a method that goes something like this:
public static String changelowertoupper()
{
String str = "CyBeRdRaGoN";
str=str.toLowerCase(Locale.ENGLISH);
return str;
}
现在我已经阅读了使用某些 Locale
s,如土耳其语,返回 i(不带点) 而不是 i(带点) 。
Now I've read that using certain Locale
s, like Turkish, "returns i (without dot) instead of i (with dot)."
使用 Locale
是否可以安全使用英国,美国,英国等?应用于字符串时,它们之间是否存在很大差异?
Is it safe to use Locale
s like UK, US, ENGLISH, etc.? Are there any big differences between them when applied to strings?
对于<$ c,哪个是最优选的区域设置
$ c>字符串 s?
Which is the most preferred Locale
for String
s?
推荐答案
我认为你应该使用语言环境,
I think you should use locale ,
我推荐这些链接作为你的问题的解决方案
并且它必须记住你的情况土耳其语
I refer to these links as solution to your problemand it has point to keep in mind in you situation "Turkish"
**FROM THE LINKS**
import java.util.Locale;
public class ToLocaleTest {
public static void main(String[] args) throws Exception {
Locale.setDefault(new Locale("lt")); //setting Lithuanian as locale
String str = "\u00cc";
System.out.println("Before case conversion is "+str+
" and length is "+str.length());// Ì
String lowerCaseStr = str.toLowerCase();
System.out.println("Lower case is "+lowerCaseStr+
" and length is "+lowerCaseStr.length());// iı`
}
}
为了使其更安全,您可以使用另一种方法
toLowerCase(Locale.English)和始终将语言环境覆盖为英语。
但是你没有国际化。
To make it safer, you may use another method toLowerCase(Locale.English) and override the locale to English always. But then you are not internationalized.
所以关键是,toLowerCase()是特定于语言环境的。
So the crux is, toLowerCase() is locale specific.
Dotless-i,是一个小写的'我'没有点。这个角色的大写字母是通常的我。还有另一个角色,我带点。这个字符的小写字母通常是小写的i。
Dotless-i, is a lowercase 'i' without dot. The uppercase of this character is the usual "I". There is another character, "I with dot". The lowercase of this character is the usual lowercase "i".
你注意到了这个问题吗?这种不对称的转换在编程中引起严重的问题。我们主要在Java应用程序中遇到这个问题,因为(IMHO)toLowerCase和toUpperCase函数的实现很差。
Have you noticed the problem? This unsymetrical conversion causes a serious problem in programming. We face this problem mostly in Java applications because of (IMHO) poor implementation of toLowerCase and toUpperCase functions.
在Java中,String.toLowerCase()方法根据字符串将字符转换为小写到默认语言环境。如果您的应用程序在土耳其语语言环境中工作,这会导致问题,特别是如果您将此函数用于文件名或必须遵守某个字符集的URL。
In Java, String.toLowerCase() method converts characters to lowercase according to the default locale. This causes problems if your application works in Turkish locale and especially if you are using this function for a file name or a url that must obey a certain character set.
我有以前有两个严肃的例子:如果XPage位于名称中包含I的数据库中,脚本库的编号错误,其名称中包含i,而XSP Manager则出错。
I have blogged about two serious examples before: The compile errors with Script libraries with "i" in their names and XSP Manager's fault if an XPage is in a database with "I" in its name.
正如我所说,历史悠久。例如,在某些R7版本中,如果路由器的名称以I开头,则路由器无法向收件人发送消息。在R8之前,邮件报告代理未在土耳其语语言环境中运行。任何拥有土耳其语语言环境的人都无法安装Lotus Notes 8.5.1(这是真的!)。这个列表继续......
There is a long history, as I said. For instance in some R7 version, router was unable to send a message to a recipient if his/her name starts with "I". Message reporting agents was not running in Turkish locale until R8. Anyone with Turkish locale could not install Lotus Notes 8.5.1 (it's real!). The list goes on...
土耳其几乎没有beta测试人员,客户也不会因为这些问题而打开PMR。所以这些问题并没有成为开发团队的首要任务。
There is almost no beta tester from Turkey and customers don't open PMR for these problems. So these problems are not going up to the first priority for development teams.
甚至Java团队也在最新文档中添加了一个特殊警告:
Even Java team has added a special warning to the latest documentation:
请阅读我不能理解的链接张贴所有这些这是对你的评论的回复
PLEASE READ THE LINKS I CANT POST ALL OF IT "THIS IS REPLY TO YOUR COMMENT"
这篇关于将语言环境与Java的toLowerCase()和toUpperCase()一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!