Here you can find the source of removeAccents(String s)
Parameter | Description |
---|---|
s | String to be unaccented. |
public static String removeAccents(String s)
//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(); } }