Java String Double Quote doubleQuotedString(String str)

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

Description

double Quoted String

License

Open Source License

Declaration

public static String doubleQuotedString(String str) 

Method Source Code

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

public class Main {
    public static String doubleQuotedString(String str) {
        StringBuilder result = new StringBuilder("\"");
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            if (ch == '\n') {
                result.append("\\n");
                continue;
            }//  w  ww. ja v a 2  s  .c  om
            if (ch == '\r') {
                result.append("\\r");
                continue;
            }
            if (ch == '\t') {
                result.append("\\t");
                continue;
            }
            if (ch == '"' || ch == '\\' || ch == '$')
                result.append('\\');
            result.append(ch);
        }
        result.append('"');
        return result.toString();
    }
}

Related

  1. doublequote(String str, boolean escapeHtml)
  2. doubleQuote(String string)
  3. doubleQuote(String value)
  4. doubleQuote(String x)
  5. doubleQuoted(String string)
  6. doublequoteEncode(String str)
  7. doubleQuoteIfNecessary(String string)
  8. doubleQuoteIfNotNull(String str)
  9. doubleQuotes(CharSequence stringToDoubleQuote, boolean escapeDoubleQuote)