Is there a way to get rid of accents and convert a whole string to regular letters?

前端 未结 12 2279
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 04:58

Is there a better way for getting rid of accents and making those letters regular apart from using String.replaceAll() method and replacing letters one by one?

12条回答
  •  暖寄归人
    2020-11-22 05:20

    System.out.println(Normalizer.normalize("àèé", Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", ""));
    

    worked for me. The output of the snippet above gives "aee" which is what I wanted, but

    System.out.println(Normalizer.normalize("àèé", Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", ""));
    

    didn't do any substitution.

提交回复
热议问题