Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试用两个反斜杠替换字符串中的反斜杠,如下所示:
s = s.replace("\\", "\\\\");
但是,它什么也没做。示例字符串:
s="\r\nHi\r\n";
该字符串不包含反斜杠,它包含\r转义序列。
\r
工作示例
例如
var str = "\r\n"; var replaced = str.replace('\r\n', '\\r\\n'); alert(replaced);
然后将显示警报\r\n
\r\n