Removes the double quote from the start and end of the supplied string if it starts and ends with this character : String Escape « Data Type « Java






Removes the double quote from the start and end of the supplied string if it starts and ends with this character

      
/*
 * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
 *
 * Licensed under the Aduna BSD-style license.
 */

public class StringUtil {


  /**
   * Removes the double quote from the start and end of the supplied string if
   * it starts and ends with this character. This method does not create a new
   * string if <tt>text</tt> doesn't start and end with double quotes, the
   * <tt>text</tt> object itself is returned in that case.
   * 
   * @param text
   *        The string to remove the double quotes from.
   * @return The trimmed string, or a reference to <tt>text</tt> if it did
   *         not start and end with double quotes.
   */
  public static String trimDoubleQuotes(String text) {
    int textLength = text.length();

    if (textLength >= 2 && text.charAt(0) == '"' && text.charAt(textLength - 1) == '"') {
      return text.substring(1, textLength - 1);
    }

    return text;
  }
} // end class

   
    
    
    
    
    
  








Related examples in the same category

1.Ends With Ignore Case
2.Escape commas in the string using the default escape char
3.Escapes characters that have special meaning to regular expressions
4.unEscape String
5.Quote string
6.Unquote string
7.Escape string
8.Unescape any C escape sequences (\n, \r, \\, \ooo, etc) and return the resulting string.
9.Unescape any MySQL escape sequences.
10.Escape a string for use inside as XML element content. This escapes less-than and ampersand, only.
11.Escape a string for use inside as XML single-quoted attributes.
12.Replace String With Escape