Java String Accent removeAccents(String s)

Here you can find the source of removeAccents(String s)

Description

Removes accents from all letters according to Unicode spec.

License

Open Source License

Parameter

Parameter Description
s String to be unaccented.

Return

Unaccented string.

Declaration

public static String removeAccents(String s) 

Method Source Code

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

import java.text.Normalizer;

public class Main {
    /**//from   w  w w. jav  a 2 s. c  o m
     * Removes accents from all letters according to Unicode spec.
     * @param s String to be unaccented.
     * @return Unaccented string.
     */
    public static String removeAccents(String s) {
        // Convert accented chars to equivalent unaccented char + dead char accent 
        // pair. See http://www.unicode.org/unicode/reports/tr15/tr15-23.html to 
        // understand the NFD transform.
        final String normalized = Normalizer.normalize(s,
                Normalizer.Form.NFD);
        // Remove the dead char accents, leaving just the unaccented chars.
        // Stripped string should have the same length as the original accented one.
        StringBuilder sb = new StringBuilder(s.length());

        for (int i = 0; i < normalized.length(); i++) {
            char c = normalized.charAt(i);
            if (c == '\u0111' || c == '\u0110') { //dodato jer normalizer nije pretvarao 
                sb.append("dj");
            } else if (Character.getType(c) != Character.NON_SPACING_MARK) {
                sb.append(c);
            }
        }
        return sb.toString();
    }
}

Related

  1. removeAccent(String strIn)
  2. removeAccents(final String s)
  3. removeAccents(final String value)
  4. removeAccents(final String value)
  5. removeAccents(String input)
  6. removeAccents(String str)
  7. removeAccents(String text)
  8. removeAccents(String textWithAccent)
  9. removeAccentsAndNonStandardCharacters(String string)