Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@s9134131
Last active July 16, 2018 14:20
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 s9134131/72f4b7996492852f5b0b911fd0922e5b to your computer and use it in GitHub Desktop.
Save s9134131/72f4b7996492852f5b0b911fd0922e5b to your computer and use it in GitHub Desktop.
public static String convertDecimalNCRToString(String txt){
Pattern p = Pattern.compile("&#(.*?);");
Matcher m = p.matcher(txt);
while(m.find()){
String match = m.group(1);
if(!match.startsWith("x")){
txt = txt.replaceAll("&#" + m.group(1) + ";", "" + (char)Integer.parseInt(m.group(1)));
}else{
txt = txt.replaceAll("&#" + m.group(1) + ";", "" + (char)Integer.parseInt(m.group(1).replaceFirst("x", ""), 16));
}
}
return txt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment