I have a list with some Belgian cities with diacritic characters: (Liège, Quiévrain, Franière, etc.) and I would like to transform these special characters to compare with a lis
As of Java 6, you can use java.text.Normalizer:
public String unaccent(String s) {
String normalized = Normalizer.normalize(s, Normalizer.Form.NFD);
return normalized.replaceAll("[^\\p{ASCII}]", "");
}
Note that in Java 5 there is also a sun.text.Normalizer
, but its use is strongly discouraged since it's part of Sun's proprietary API and has been removed in Java 6.