Skip to content

Instantly share code, notes, and snippets.

@agentgt
Created July 22, 2011 18:19
Show Gist options
  • Select an option

  • Save agentgt/1100035 to your computer and use it in GitHub Desktop.

Select an option

Save agentgt/1100035 to your computer and use it in GitHub Desktop.
Gracefully downgrading a UTF-8 String with weird characters to ASCII
public static String toAscii(String str) {
if (str == null) return null;
return Normalizer.normalize(str, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]","");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment