Java String Quote quoteIdentifier(String s)

Here you can find the source of quoteIdentifier(String s)

Description

Enclose a string with double quotes.

License

Open Source License

Parameter

Parameter Description
s the text

Return

the double quoted text

Declaration

public static String quoteIdentifier(String s) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/* w  ww.  j  av a2 s . co m*/
     * Enclose a string with double quotes. A double quote inside the string is
     * escaped using a double quote.
     *
     * @param s the text
     * @return the double quoted text
     */
    public static String quoteIdentifier(String s) {
        int length = s.length();
        StringBuilder buff = new StringBuilder(length + 2);
        buff.append('\"');
        for (int i = 0; i < length; i++) {
            char c = s.charAt(i);
            if (c == '"') {
                buff.append(c);
            }
            buff.append(c);
        }
        return buff.append('\"').toString();
    }
}

Related

  1. quoteIdentifier(String identifier)
  2. quoteIdentifier(String identifier, boolean isPedantic)
  3. quoteIdentifier(String identifier, boolean isPedantic)
  4. quoteIdentifier(String identifier, String quoteChar)
  5. quoteIdentifier(String s)
  6. quoteIfCeylonKeyword(String name)
  7. quoteIfNeeded(String id)
  8. quoteIfNeeded(String input)
  9. quoteIfNeeded(String source)