我正在处理第 3 方 API/Web 服务,他们只允许在其 XML 中使用 latin-1 字符集。是否有现有的 API/方法可以查找并替换字符串中的所有非 latin-1 字符?
例如:凯文
有办法制作那个凯文吗?
最佳答案
使用 ICU4J,
public String removeAccents(String text) {
return Normalizer.decompose(text, false, 0)
.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
}
我在http://glaforge.appspot.com/article/how-to-remove-accents-from-a-string找到了这个例子
在 java 1.6 中,必要的规范化器可能是内置的。
关于java - 替换所有非 latin-1 字符的 API 或方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11232201/