Java String Unquote unquote(String str)

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

Description

Returns the given quoted string without quotation marks.

License

Open Source License

Parameter

Parameter Description
str quoted string

Exception

Parameter Description
IllegalArgumentExceptionif str doesn't have a leading ora trailing quotation mark
NullPointerExceptionif str is null

Return

string without quotation marks

Declaration

public static String unquote(String str) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from w  ww . j  a  v a  2  s. co  m*/
     * Returns the given quoted string without quotation marks.
     *
     * @param str quoted string
     * @return string without quotation marks
     * @throws IllegalArgumentException  if {@code str} doesn't have a leading or
     *                                   a trailing quotation mark
     * @throws NullPointerException  if {@code str} is {@code null}
     */
    public static String unquote(String str) {
        int lastIndex = str.length() - 1;
        if (lastIndex <= 0 || str.charAt(0) != '"'
                || str.charAt(lastIndex) != '"') {
            throw new IllegalArgumentException(
                    "Attempting to unquote string without quotes!");
        }

        return str.substring(1, lastIndex);
    }
}

Related

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