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