Java Java String Format toJavaScriptSafeString(String content)

Here you can find the source of toJavaScriptSafeString(String content)

Description

Convert a string to a JavaScript safe string (escape quotes and remove cr and lf).

License

Open Source License

Parameter

Parameter Description
content the input string

Return

the JavaScript safe result.

Declaration

public static String toJavaScriptSafeString(String content) 

Method Source Code

//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;
    }
}

Related

  1. toJavaPath(String path)
  2. toJavaPath(String path)
  3. toJavaPattern(String pattern)
  4. toJavascriptArray(String[][] Vals)
  5. toJavaScriptEncode(String string)
  6. toJavaSecs(long secs)
  7. toJavaSourceType(String type)
  8. toJavaStaticIdentifier(String string)
  9. toJavaString(final String s)