Java String Unquote unquote(String quoted)

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

Description

remove the surrounding quotation mark and restore 2 successive quotation marks to 1

License

Open Source License

Parameter

Parameter Description
quoted a parameter

Declaration

public static String unquote(String quoted) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  w w  w .j  ava  2 s  .  c o  m
      * remove the surrounding quotation mark and restore 2 successive quotation marks to 1
      * 
      * @param quoted
      * @return
      */
    public static String unquote(String quoted) {
        String content = quoted;
        if (quoted.indexOf("'") == 0 && quoted.lastIndexOf("'") == quoted.length() - 1 && quoted.length() > 1) {
            content = quoted.substring(1, quoted.length() - 1).replaceAll("''", "'");
        } else if (quoted.indexOf("\"") == 0 && quoted.lastIndexOf("\"") == quoted.length() - 1
                && quoted.length() > 1) {
            content = quoted.substring(1, quoted.length() - 1).replaceAll("\"\"", "\"");
        } else if (quoted.indexOf("[") == 0 && quoted.lastIndexOf("]") == quoted.length() - 1
                && quoted.length() > 1) {
            content = quoted.substring(1, quoted.length() - 1);
        }
        return content;
    }
}

Related

  1. unquote(String message)
  2. unquote(String name)
  3. unquote(String name)
  4. unquote(String quoted)
  5. unquote(String quoted)
  6. unquote(String quotedString)
  7. unquote(String s)
  8. unquote(String s)
  9. unquote(String s)