DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Thomas has posted 33 posts at DZone. View Full User Profile

Remove Symbols And Accents From A String In Java

04.16.2010
| 4251 views |
  • submit to reddit
        
  public static String normalizeSymbolsAndAccents(String str) {
    str = org.apache.commons.lang.StringUtils.defaultString(str);
    String nfdNormalizedString = Normalizer.normalize(str, Normalizer.Form.NFD);
    Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
    return pattern.matcher(nfdNormalizedString).replaceAll("");
  }