Here you can find the source of unquote(String maybeQuoted)
Parameter | Description |
---|---|
maybeQuoted | A String which may or may not be surrounded with single or double quotes. |
public static String unquote(String maybeQuoted)
//package com.java2s; //License from project: Open Source License public class Main { /**//w ww .j a va 2 s . c om * Removes single or double quotes which surround a String. Matching quotes must appear at the * beginning and end of the String for it to be considered quoted. * @param maybeQuoted A String which may or may not be surrounded with single or double quotes. * @return The input String with zero or one pairs of surrounding quotes removed, or null if the input String is null. * @author: Sam Barnum */ public static String unquote(String maybeQuoted) { if (maybeQuoted == null || maybeQuoted.length() < 2) return maybeQuoted; boolean isQuoted = false; int len = maybeQuoted.length(); if (maybeQuoted.charAt(0) == '"' && maybeQuoted.charAt(len - 1) == '"') isQuoted = true; else if (maybeQuoted.charAt(0) == '\'' && maybeQuoted.charAt(len - 1) == '\'') isQuoted = true; if (isQuoted) { maybeQuoted = maybeQuoted.substring(1, len - 1); } return maybeQuoted; } }