Created
January 27, 2014 14:41
-
-
Save omarnetfr/8649703 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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