L
laredotornado
Hi,
I'm using Java 6. I want to output code for a Javascript variable ...
String jsValue = escapeForJS(value);
String expression = "storedVars['myVar'] = \"" + jsValue + "\";";
Is there anything standard that will do this? I came up with my own
function, but I don't want to worry about leaving anything out.
/* creates a JS expression that can be used within quotes. */
private String escapeForJS(String value) {
value = value.replace("\n", "\\n");
value = value.replace("\r", "\\r");
value = value.replace("\"", "\\\"");
return value;
}
- Dave
I'm using Java 6. I want to output code for a Javascript variable ...
String jsValue = escapeForJS(value);
String expression = "storedVars['myVar'] = \"" + jsValue + "\";";
Is there anything standard that will do this? I came up with my own
function, but I don't want to worry about leaving anything out.
/* creates a JS expression that can be used within quotes. */
private String escapeForJS(String value) {
value = value.replace("\n", "\\n");
value = value.replace("\r", "\\r");
value = value.replace("\"", "\\\"");
return value;
}
- Dave