Here you can find the source of removeAccents(final String s)
Parameter | Description |
---|---|
s | a parameter |
public static String removeAccents(final String s)
//package com.java2s; //License from project: Open Source License import java.text.Normalizer; import java.util.regex.Pattern; public class Main { private static final Pattern DIACRITICALMARKS_PATTERN = Pattern.compile("\\p{InCombiningDiacriticalMarks}+"); /**/* www. j a v a 2 s .c o m*/ * replace accentuated characters by their non-accentuated equivalents. * * @param s * @return */ public static String removeAccents(final String s) { String nfdNormalizedString = Normalizer.normalize(s, Normalizer.Form.NFD); return DIACRITICALMARKS_PATTERN.matcher(nfdNormalizedString).replaceAll(""); } /** * trims the string, removes accents, replaces spaces by underscores et remove all non-ascii characters. Also adds an underscore at the beginning if the * string starts with a number. * * This method may be useful when transforming a random string into a variable name or file name, for example. * * @param s * string to modify * @return modified string */ public static String normalize(final String s) { String tmp = removeAccents(s).replaceAll("[^a-zA-Z0-9_]", "").trim().replaceAll("\\p{Space}", "_"); if (s.matches("^[0-9].*")) { return "_" + tmp; } else { return tmp; } } }