Skip to content

Instantly share code, notes, and snippets.

@michalbcz
Last active March 17, 2017 12:18
Show Gist options
  • Save michalbcz/7320173 to your computer and use it in GitHub Desktop.
Save michalbcz/7320173 to your computer and use it in GitHub Desktop.
replacing characters with diacritic (national characters) with variant without diacritic eg. replace Á to A..etc.
public final class StringUtils {
private StringUtils() { /* cannot be instantiated */ }
/**
* <b>WORKS ONLY IN JAVA 1.6 AND ABOVE !!!</b>
*
* @param textWithDiacritic
*/
public static String removeDiacritics(String textWithDiacritic) {
String decomposed = java.text.Normalizer.normalize(textWithDiacritic, Normalizer.Form.NFD);
return decomposed.replaceAll("\\\\p{InCombiningDiacriticalMarks}+", "");
}
}
@michalbcz
Copy link
Author

@michalbcz
Copy link
Author

javascript verze

const str = "Crème Brulée" str.normalize('NFD').replace(/[\u0300-\u036f]/g, "")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment