如该答案中所述,以下代码应该起作用:
String s = "口水雞 hello Ä"; String s1 = Normalizer.normalize(s, Normalizer.Form.NFKD); String regex = "[\p{InCombiningDiacriticalMarks}\p{IsLm}\p{IsSk}]+"; String s2 = new String(s1.replaceAll(regex, "").getBytes("ascii"), "ascii"); System.out.println(s2); System.out.println(s.length() == s2.length());输出为
??? hello Atrue
因此,您首先要删除双引号,然后转换为ascii。非ASCII字符将成为问号。



