import java.io.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class RemoveAccents {
/**
* This method remove accents from a string.
* @param str String to remove accents.
* @return String Obtains the string without accents.
*/
public static String removeAccents(String str) {
//Variable to store the string without accents
String nfdNormalizedString = Normalizer.normalize(str, Normalizer.Form.NFD);
Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
return pattern.matcher(nfdNormalizedString).replaceAll("");
}
/**
* One Example
*/
public static void main(String args[]) throws IOException {
RemoveAccents removeAccents= new RemoveAccents ();
//Example
String str = "Álvaro";
String strWithoutAccents = removeAccents.removeAccents(str);
//Output
System.out.println("String without accents is :" + strWithoutAccents); //Alvaro
}
}
For further actions, you may consider blocking this person and/or reporting abuse
Oldest comments (0)