Java String Quote quote(String str, String quoteChar)

Here you can find the source of quote(String str, String quoteChar)

Description

Quote the given String with passed quoteChar.

License

LGPL

Parameter

Parameter Description
str the input String (e.g. "myString")
quoteChar Character to use for quote.

Return

the quoted String (e.g. "'myString'"), or null if the input was null

Declaration

public static String quote(String str, String quoteChar) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**/*from ww  w. j av  a  2 s  .c  om*/
     * Quote the given String with single quotes.
     *
     * @param str the input String (e.g. "myString")
     * @return the quoted String (e.g. "'myString'"), or
     *         <code>null<code> if the input was
     *         <code>null</code>
     */
    public static String quote(String str) {
        return (str != null ? "'" + str + "'" : null);
    }

    /**
     * Quote the given String with passed quoteChar.
     *
     * @param str       the input String (e.g. "myString")
     * @param quoteChar Character to use for quote.
     * @return the quoted String (e.g. "'myString'"), or
     *         <code>null<code> if the input was
     *         <code>null</code>
     */
    public static String quote(String str, String quoteChar) {
        return (str != null ? quoteChar + str + quoteChar : null);
    }
}

Related

  1. quote(String str)
  2. quote(String str)
  3. quote(String str)
  4. quote(String str)
  5. quote(String str, char c)
  6. quote(String str, StringBuffer out)
  7. quote(String string)
  8. quote(String string)
  9. quote(String string)