【发布时间】:2018-08-08 16:36:42
【问题描述】:
我有一个字符串姓氏。
我想替换特殊的保加利亚语。带有英语标准替换的波兰语字符。
例如 surname = "Tuğba Delioğlu"
最终输出字符串应该是:tugbadelioglu
为了实现这一点,我刚刚做了一系列 string.replaceAll 如下:-
surname = surname.replaceAll("ı", "i");
surname = surname.replaceAll("ł", "l");
surname = surname.replaceAll("Ł", "l");
surname = surname.replaceAll("ń", "n");
surname = surname.replaceAll("ğ", "g");
surname = surname .replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); // this will remove diacritics
String newSurname = surname.replaceAll("[^a-zA-Z]",""); // remove non A-Z characters
surname = surname.replaceAll("\\s","").toLowerCase(); // remove spaces and make lowercase
有没有更有效的方法来做到这一点,即有一个数组:- 要替换的字符 要替换的字符
然后循环遍历字符串并用数组中的表示替换每个匹配的字符?
这将是相当大的量,因此寻找最有效的方法。
【问题讨论】:
-
波兰语中
Ł的替换是L,而不是l;)
标签: java arrays string localization character