从字符串中删除重音重音、字符串

2023-09-12 04:09:55 作者:断一根琴弦,哼一曲离别

有没有办法在Android中的(据我所知)没有java.text.Normalizer,从字符串中删除任何口音。例如香水变为淡。

Is there any way in Android that (to my knowledge) doesn't have java.text.Normalizer, to remove any accent from a String. E.g "éàù" becomes "eau".

我想避免解析字符串来检查每个字符,如果可能的!

I'd like to avoid parsing the String to check each character if possible!

推荐答案

java.text.Normalizer 是那里的Andr​​oid(在最新的版本是这样)。你可以使用它。

java.text.Normalizer is there in Android (on latest versions anyway). You can use it.

修改作为参考,在这里是如何使用正规化

EDIT For reference, here is how to use Normalizer:

string = Normalizer.normalize(string, Normalizer.Form.NFD);
string = string.replaceAll("[^\\p{ASCII}]", "");

(来自链路粘贴在下面评论)

(pasted from the link in comments below)