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

Stringunescape(String s)
Unescape the specified string.
if (-1 == s.indexOf('\\')) {
    return s;
final int length = s.length();
StringBuilder buf = new StringBuilder(length);
for (int i = 0; i < length; i++) {
    char c = s.charAt(i);
    if ('\\' != c) {
...
Stringunescape(String s)
unescape
return s.replace("\\\"", "\"");
Stringunescape(String s)
unescape
if (s.indexOf('\\') < 0)
    return s;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
    char c = s.charAt(i);
    if (c == '\\' && i != (s.length() - 1)) {
        char c2 = s.charAt(i + 1);
        switch (c2) {
...
Stringunescape(String s)
unescape
StringBuffer sbuf = new StringBuffer();
int l = s.length();
int ch = -1;
int b, sumb = 0;
for (int i = 0, more = -1; i < l; i++) {
    switch (ch = s.charAt(i)) {
    case '%':
        ch = s.charAt(++i);
...
Stringunescape(String s)
Removes escaping from an RFC 5545 "text".
if (s.indexOf('\\') == -1) {
    return s;
StringBuilder result = new StringBuilder();
for (int i = 0; i < s.length(); ++i) {
    char ch = s.charAt(i);
    if (ch == '\\' && i < s.length() - 1) {
        char ch2 = s.charAt(++i);
...
Stringunescape(String s)
unescape
String out = "";
boolean esc = false;
for (char c : s.toCharArray()) {
    if (esc) {
        if (c == 'n') {
            out += '\n';
        } else if (c == 't') {
            out += '\t';
...
intunescape(String s)
Unescapes 'lt', 'gt', 'apos', 'quote' and 'amp' to the corresponding character values.
if ("apos".equals(s))
    return '\'';
if ("quot".equals(s))
    return '"';
if ("lt".equals(s))
    return '<';
if ("gt".equals(s))
    return '>';
...
Stringunescape(String s, char[] charsToEscape)
Given an escaped string returned by #escape and the original set of characters to escape, returns the original string.
StringBuilder buf = new StringBuilder(s.length());
boolean inEscapeSequence = false;
for (int i = 0; i < s.length(); i++) {
    char c = s.charAt(i);
    if (inEscapeSequence) {
        if (c != ESCAPE && !hasChar(charsToEscape, c)) {
            throw new IllegalArgumentException(c + " is not a valid escape sequence character");
        buf.append(c);
        inEscapeSequence = false;
    } else if (hasChar(charsToEscape, c)) {
        throw new IllegalArgumentException(c + " must be escaped");
    } else if (c == ESCAPE) {
        inEscapeSequence = true;
    } else {
        buf.append(c);
if (inEscapeSequence) {
    throw new IllegalArgumentException("Unterminated escape sequence");
return buf.toString();
byteunescape(String s, int i)
unescape
return (byte) Integer.parseInt(s.substring(i + 1, i + 3), 16);
Stringunescape(String s, String toUnescape)
unescape
return s.replace("\\" + toUnescape, toUnescape);