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
"\r\nHi\r\n") does not contain a backslash.\ris the escape sequence for a carriage return and\nis the escape sequence for a line feed. The resulting string value does not contain the backslash character. Just doconsole.log(s)and you will see. If you'd explain what problem you are really trying to solve, we might be able to help you.