Java String Quote QuoteValue(String str)

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

Description

Quotes a string according to RFC 5322 rules.

License

Creative Commons License

Parameter

Parameter Description
str A string object.

Return

A string object.

Declaration

public static String QuoteValue(String str) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   ww w.  ja v  a2  s  .  com
     * Quotes a string according to RFC 5322 rules.
     * @param str A string object.
     * @return A string object.
     */
    public static String QuoteValue(String str) {
        StringBuilder builder = new StringBuilder();
        builder.append('"');
        for (int i = 0; i < str.length(); ++i) {
            if (str.charAt(i) == '\\' || str.charAt(i) == '"') {
                builder.append('\\');
                builder.append(str.charAt(i));
            } else {
                builder.append(str.charAt(i));
            }
        }
        builder.append('"');
        return builder.toString();
    }
}

Related

  1. quoteStringValue(String value)
  2. quoteText(String text)
  3. quoteText(String textToQuote, boolean sbAppend)
  4. quoteTo(CharSequence cs, StringBuilder target)
  5. quoteTokenize(String clientResponse)
  6. quoteValue(String value)
  7. QuoteValueIfNeeded(String str)
  8. quoteValues(String value)
  9. quoteWhitespaces(String path)