Here you can find the source of toJavaScriptSafeString(String content)
Parameter | Description |
---|---|
content | the input string |
public static String toJavaScriptSafeString(String content)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w ww.j a v a 2 s . c o m * Convert a string to a JavaScript safe string (escape quotes and remove cr and lf). * @param content the input string * @return the JavaScript safe result. */ public static String toJavaScriptSafeString(String content) { content = content.replaceAll("'", "\\\\'"); content = content.replaceAll("\"", "\\\\\""); content = content.replaceAll("\\r\\n", ""); content = content.replaceAll("\\r", ""); content = content.replaceAll("\\n", ""); return content; } }