Java String Accent deAccent(String str)

Here you can find the source of deAccent(String str)

Description

de Accent

License

Open Source License

Declaration

private static String deAccent(String str) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.Normalizer;
import java.util.regex.Pattern;

public class Main {
    private static String deAccent(String str) {
        String nfdNormalizedString = Normalizer.normalize(str, Normalizer.Form.NFD);
        Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
        return pattern.matcher(nfdNormalizedString).replaceAll("");
    }/*from ww w  .  j  a  v  a 2 s.  co m*/

    public static String normalize(String name) {
        return normalize(name, -1);
    }

    public static String normalize(String name, int limit) {
        String normalized = deAccent(name).replaceAll("[^0-9a-zA-Z\\$_]", "");
        return limit > 0 && normalized.length() > limit ? normalized.substring(0, limit - 1) : normalized;
    }
}

Related

  1. compareIgnoreCaseAndAccent(String string1, String string2, Locale locale)
  2. deAccent(final @Nonnull String string)
  3. deAccent(String str)
  4. deAccent(String str)
  5. deleteAccents(String text)
  6. equalsIgnoreAccents(String lhs, String rhs, Locale locale)
  7. equalsIgnoreAccentsAndCase(String s1, String s2)