We translate the string “Chloé” to “Chloe” with hard-coded comparisons between special characters and their equivalent ASCII character before the comparison. This works pretty well, but is clumsy and there are probably some special characters that we forgot.
Our solution looks something like this:
public static String replaceAccents(String string) { String result = null; if (string != null) { result = string; result = result.replaceAll("[àáâãåä]", "a"); result = result.replaceAll("[ç]", "c"); result = result.replaceAll("[èéêë]", "e"); result = result.replaceAll("[ìíîï]", "i"); result = result.replaceAll("[ñ]", "n"); result = result.replaceAll("[òóôõö]", "o"); result = result.replaceAll("[ùúûü]", "u"); result = result.replaceAll("[ÿý]", "y"); result = result.replaceAll("[ÀÁÂÃÅÄ]", "A"); result = result.replaceAll("[Ç]", "C"); result = result.replaceAll("[ÈÉÊË]", "E"); result = result.replaceAll("[ÌÍÎÏ]", "I"); result = result.replaceAll("[Ñ]", "N"); result = result.replaceAll("[ÒÓÔÕÖ]", "O"); result = result.replaceAll("[ÙÚÛÜ]", "U"); result = result.replaceAll("[Ý]", "Y"); } return result; }
So I'm curious to get a good answer to this question!
Lukas Eder
source share