Java String Quote quote(String str)

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

Description

This is the static method, that quotes a string.

License

Open Source License

Declaration

public static String quote(String str) 

Method Source Code

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

public class Main {
    /**/* ww w.  j a  va  2s .  co  m*/
     * This is the static method, that quotes a string.
     */
    public static String quote(String str) {
        StringBuffer result = new StringBuffer("\"");
        for (int i = 0; i < str.length(); i++) {
            char c;
            switch (c = str.charAt(i)) {
            case '\0':
                result.append("\\0");
                break;
            case '\\':
                result.append("\\\\");
                break;
            case '\"':
                result.append("\\\"");
                break;
            default:
                result.append(str.charAt(i));
            }
        }
        return result.append("\"").toString();
    }
}

Related

  1. quote(String str)
  2. quote(String str)
  3. quote(String str)
  4. quote(String str)
  5. quote(String str)
  6. quote(String str)
  7. quote(String str)
  8. quote(String str)
  9. quote(String str)