Java String Unquote unquote(String str)

Here you can find the source of unquote(String str)

Description

unquote

License

Open Source License

Declaration

public static String unquote(String str) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String unquote(String str) {
        assert isQuoted(str) : "Trying to unquote an unquoted string: " + str;
        // Detect which types of quotes are used and unescape accordingly.
        char qval = str.charAt(0);

        // Strip the existing quotes first.
        str = str.substring(1, str.length() - 1);
        if (qval == '\'') {
            str = str.replace("\\'", "'");
        } else {// w  w  w . j  a va2  s.co  m
            assert qval == '"' : "Unknown quoted string format: " + str;
            str = str.replace("\\\"", "\"");
        }
        return str;
    }

    public static boolean isQuoted(String str) {
        if (str.startsWith("\"") && str.endsWith("\""))
            return true;
        if (str.startsWith("'") && str.endsWith("'"))
            return true;
        return false;
    }
}

Related

  1. unquote(String s)
  2. unquote(String s)
  3. unquote(String s, char c)
  4. unquote(String str)
  5. unquote(String str)
  6. unquote(String str)
  7. unquote(String str)
  8. unquote(String str)
  9. unquote(String string)