简体   繁体   中英

Eliminating backslashes from JavaScript strings

Using JavaScript I would like to eliminate \\ .
Currently I get back \\"Sequence\\" , but would like to remove \\ and get "Sequence" instead. Tried *.replace(/\\\\/g, ''); , but it did not work.

Remember, in JavaScript \\ is an escape character. So when you say

\"Sequence\"

I'm guessing the string is actually "<double quote>Sequence<double quote>"

In other words, there is no back slash for you to remove.


Or, if I'm reading the question wrongly, note that replace does NOT modify the string in question. So you wouldn't do

foo.replace(/\\/g, '');

but rather

foo = foo.replace(/\\/g, '');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM