Java tutorial
//package com.java2s; public class Main { public static String escapeJava(String doco) { if (doco == null) return ""; StringBuilder b = new StringBuilder(); for (char c : doco.toCharArray()) { if (c == '\r') b.append("\\r"); else if (c == '\n') b.append("\\n"); else if (c == '"') b.append("'"); else b.append(c); } return b.toString(); } }