The string doesn't contain a backslash, it contains the \r
escape sequence.
For example
var str = "\r\n";
var replaced = str.replace('\r\n', '\\r\\n');
alert(replaced);
Then the alert will be shown \r\n
题
I'm trying to replace backslashes in my string with two backslashes like so:
s = s.replace("\\", "\\\\");
But, it doesn't do anything. Example string:
s="\r\nHi\r\n";
解决方案
The string doesn't contain a backslash, it contains the \r
escape sequence.
For example
var str = "\r\n";
var replaced = str.replace('\r\n', '\\r\\n');
alert(replaced);
Then the alert will be shown \r\n