建议以下代码:
package org.apache.creadur.rat2.core.ds;
import java.util.Locale;
public class TestUsAsciiLocale {
public static void main(String[] pArgs) throws Exception {
final String capitalLetterAe = "\u00c4";
final String smallLetterAe = "\u00e4";
if (capitalLetterAe.toLowerCase(Locale.GERMANY).equals(smallLetterAe)) {
System.out.println("Capital Ae, and small ae are the same (case insensitive) in the german Locale.");
}
if (capitalLetterAe.toLowerCase(Locale.US).equals(smallLetterAe)) {
System.out.println("Capital Ae, and small ae are the same (case insensitive) in the US Locale.");
}
}
}
输出如下:
Capital Ae, and small ae are the same (case insensitive) in the german Locale.
Capital Ae, and small ae are the same (case insensitive) in the US Locale.
我觉得这很令人惊讶。我希望美国的Ascii Locale能够完全对待[a-zA-Z] 作为大/小写。
谢谢,
约亨
答案 0 :(得分:1)
您的代码中存在错误:
if (capitalLetterAe.toLowerCase(Locale.GERMANY).equals(smallLetterAe)) {
System.out.println("Capital Ae, and small ae are the " +
"same (case insensitive) in the US Locale.");
}
您正在使用Locale.GERMANY
,但在美国区域设置"中显示消息"。
答案 1 :(得分:1)
import xlrd
file_location = "C:/attach/Source.xlsx"
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_index(1)
for row in range(sheet.nrows):
cell = sheet.cell(row, 1)
print(cell.value)
的javadoc非常清楚:
使用给定Locale的规则将此String中的所有字符转换为小写。案例映射基于Character类指定的Unicode标准版本。由于大小写映射并不总是1:1的char映射,因此生成的String可能与原始String的长度不同。
这意味着Locale参数用于检索转换规则。也许你把它与Charset混淆了,这是不同的东西。
答案 2 :(得分:1)
Unicode具有默认case mapping。 Java String.toLowerCase(Locale)使用默认值,其中没有为指定的Locale的字符串大小写映射提供“定制”数据。如果字母在使用它们的每个语言环境中都有大小写更改,而不是在不使用它们的语言环境中,则会更令人惊讶。
无论如何,BTW-English使用的字母数比A-Z和a-z多。你有这个天线了。