Java Java String Format toJavaScriptEncode(String string)

Here you can find the source of toJavaScriptEncode(String string)

Description

to Java Script Encode

License

Apache License

Declaration

public static String toJavaScriptEncode(String string) 

Method Source Code

//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 + "\"";
    }
}

Related

  1. toJavaPackageName(String name)
  2. toJavaPath(String path)
  3. toJavaPath(String path)
  4. toJavaPattern(String pattern)
  5. toJavascriptArray(String[][] Vals)
  6. toJavaScriptSafeString(String content)
  7. toJavaSecs(long secs)
  8. toJavaSourceType(String type)
  9. toJavaStaticIdentifier(String string)