Java String Accent removeAccentuation(String str)

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

Description

remove Accentuation

License

Apache License

Parameter

Parameter Description
str the string to read from

Return

a new string in which all accentuated characters from str have been replaced by their unaccentuated equivalent.

Declaration

public static String removeAccentuation(String str) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.Normalizer;

public class Main {
    /**//from www .  ja v  a 2s  .co m
     * @param str the string to read from
     * @return a new string in which all accentuated characters from <code>str</code> have been replaced
     *         by their unaccentuated equivalent.
     */
    public static String removeAccentuation(String str) {
        // trivial cases (null, empty or simple string)
        if (str == null || str.isEmpty() || str.matches("[\\w\\s\\.\\,\\;\\:\\!\\?\\+]*"))
            return str;

        /**
         * first split compounded characters into their canonical decomposition,
         * then, remove all characters that are diacritiques.
         *
         * @see http://glaforge.free.fr/weblog/index.php?itemid=115
         * @see http://www.unicode.org/fr/charts/PDF/U0300.pdf
         */
        return Normalizer.normalize(str, Normalizer.Form.NFD).replaceAll("[\u0300-\u036f]", "");
    }
}

Related

  1. removeAccents(String s)
  2. removeAccents(String str)
  3. removeAccents(String text)
  4. removeAccents(String textWithAccent)
  5. removeAccentsAndNonStandardCharacters(String string)
  6. replaceAccent(String strInit)
  7. replaceAccentedChars(StringBuilder buffer)
  8. replaceAccents(String string)
  9. stripAccents(final String input)