Skip to content

Instantly share code, notes, and snippets.

@rickcrawford
Last active January 1, 2016 19:09
Show Gist options
  • Save rickcrawford/8188206 to your computer and use it in GitHub Desktop.
Save rickcrawford/8188206 to your computer and use it in GitHub Desktop.
Convert strings with ascii escaped characters to a valid java string. For example \x04 would escape to \n
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
public class Utils {
public static String decodeHex(String str) {
if (StringUtils.isBlank(str)) {
return str;
}
return StringEscapeUtils.unescapeJava(
str.replaceAll("(?i)\\\\x([0-9a-f]{2})", "\\\\u00$1"))
.trim();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment