Java tutorial
//package com.java2s; public class Main { public static String addEscpage(String str) { char[] cs = str.toCharArray(); StringBuilder sb = new StringBuilder("\""); int length = cs.length; for (int i = 0; i < length; i++) { if (cs[i] == '\"' || cs[i] == '\t' || cs[i] == '\n') { sb.append("\\"); } sb.append(cs[i]); } sb.append("\""); return sb.toString(); } }