Java Utililty Methods String Unescape

List of utility methods to do String Unescape

Description

The list of methods to do String Unescape are organized into topic(s).

Method

StringunEscapeString(String input)
un Escape String
return input.replaceAll("&amp;lt;", "<").replaceAll("&amp;gt;", ">");
StringunescapeString(String input)
Convert sequences of characters (into an input string) representing an escape sequence into the corresponding escape sequences
StringBuilder buf = new StringBuilder("");
int i = 0;
while (i < input.length()) {
    char currChar = input.charAt(i);
    if ((currChar == '\\') && (i < (input.length() - 1))) {
        char toAdd = 0;
        char nextChar = input.charAt(++i);
        if (nextChar == '0') {
...
StringunescapeString(String oldstr)
unescape_perl_string()

Tom Christiansen Sun Nov 28 12:55:24 MST 2010

It's completely ridiculous that there's no standard unescape_java_string function.

if ((oldstr.charAt(0) != '"' || oldstr.charAt(oldstr.length() - 1) != '"')
        && (oldstr.charAt(0) != '\'' || oldstr.charAt(oldstr.length() - 1) != '\'')) {
oldstr = oldstr.substring(1, oldstr.length() - 1);
StringBuilder newstr = new StringBuilder(oldstr.length());
boolean saw_backslash = false;
for (int i = 0; i < oldstr.length(); i++) {
    int cp = oldstr.codePointAt(i);
...
StringunescapeString(String s)
Unescapes an escaped Unicode string.
int backSlashIdx = s.indexOf('\\');
if (backSlashIdx == -1) {
    return s;
int startIdx = 0;
int sLength = s.length();
StringBuilder sb = new StringBuilder(sLength);
while (backSlashIdx != -1) {
...
StringunescapeString(String s)
unescape String
if (s.indexOf('\\') == -1) {
    return s;
StringBuilder sb = new StringBuilder(s.length());
for (int i = 0; i < s.length(); i++) {
    char ch = s.charAt(i);
    if (ch == '\\') {
        int j = i + 1;
...
StringunescapeString(String s)
unescape String
String value = s;
value = value.replaceAll("^((?<!\\\\) )*", "");
value = value.replaceAll("((?<!\\\\) )*$", "");
value = value.replaceAll("\\\\(\\\\\\\\)* ", " ");
value = value.replaceAll("\\\\(\\\\\\\\)*,", ",");
return value;
StringunescapeString(String s, char enclosed)
unescape String
if (s.charAt(0) != enclosed)
    return s;
String reg = "\\\\" + enclosed;
String replaced = s.replaceAll(reg, Character.toString(enclosed));
return replaced.substring(1, replaced.length() - 1);
StringunEscapeString(String str)
Unescape commas in the string using the default escape char
return unEscapeString(str, ESCAPE_CHAR, COMMA);
charunEscapeString(String str)
un Escape String
if (str.equalsIgnoreCase("&lt;"))
    return '<';
else if (str.equalsIgnoreCase("&gt;"))
    return '>';
else if (str.equalsIgnoreCase("&amp;"))
    return '&';
else if (str.equalsIgnoreCase("&quot;"))
    return '\"';
...
StringunescapeString(String str)
unescape String
return unescapeString(str, false, true);