Skip to content

Instantly share code, notes, and snippets.

@omarnetfr
Created January 27, 2014 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omarnetfr/8649703 to your computer and use it in GitHub Desktop.
Save omarnetfr/8649703 to your computer and use it in GitHub Desktop.
import java.text.Normalizer;
import java.util.regex.Pattern;
public class StringUtil {
public static String stripAccents(String originalString) {
String normalizedString = Normalizer.normalize(originalString, Normalizer.Form.NFD);
Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
return pattern.matcher(normalizedString).replaceAll("");
}
public static void main(String arg[]) {
// Text with accents
String stringWithAccents = "Chaîne de caractère, détail, fenêtre";
// Strip accents
String stringWithoutAccents = stripAccents(stringWithAccents);
System.out.println(stringWithoutAccents);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment