Here you can find the source of toJavaScriptEncode(String string)
public static String toJavaScriptEncode(String string)
//package com.java2s; //License from project: Apache License public class Main { /***********************************************************************/ public static String toJavaScriptEncode(String string) { if (string == null) { return "null"; }/*from w ww .j av a 2s . c om*/ string = string.replaceAll("\"", "\\\\\""); string = string.replaceAll("\r", "\\\\r"); string = string.replaceAll("\n", "\\\\n"); return "\"" + string + "\""; } }