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
This is the simplest solution I've found so far and it works perfectly in our applications.
Normalizer.normalize(string, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
But I don't know if the Normalizer is available on the Android platform.
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.