字符串中的所有字符不受支持的Efficently更换 [英] Efficently Replacement of all unsupported chars in a String
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/1008802/converting-symbols-accent-letters-to-english-alphabet\">Converting符号,雅绅特来函英文字母
我需要替换所有重音的字符,如
I need to replace all accented characters, such as
"à", "é", "ì", "ò", "ù"
与
"a'", "e'", "i'", "o'", "u'"...
因为他们已经保存重装后用重音字符的字符串嵌套一个问题。
because of an issue with reloading nested strings with accented characters after they've been saved.
有没有办法做到这一点,而无需使用不同的字符串替换所有字符?
Is there a way to do this without using different string replacement for all chars?
例如,我会preFER避免做
For example, I would prefer to avoid doing
text = text.replace("a", "a'");
text2 = text.replace("è", "e'");
text3 = text2.replace("ì", "i'");
text4 = text3.replace("ò", "o'");
text5 = text4.replace("ù", "u'");
等。
推荐答案
这个我试过从这个<一个href=\"http://stackoverflow.com/questions/1008802/converting-symbols-accent-letters-to-english-alphabet\">post它似乎工作。
I tried this from this post it seems to work.
String str= Normalizer.normalize(str, Normalizer.Form.NFD);
str= str.replaceAll("\\p{InCombiningDiacriticalMarks}+", "'");
编辑:
但用组合变音标记,有一个副作用,就是你不能 A A A
这篇关于字符串中的所有字符不受支持的Efficently更换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!