Here you can find the source of quote(String str)
public static String quote(String str)
//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(); } }