Remove all backslashes in Javascript

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 21:55:12

问题


How to remove all backslash in a JavaScript string ?

var str = "one thing\\\'s for certain: power blackouts and surges can damage your equipment.";

I want output like

one thing's for certain: power blackouts and surges can damage your equipment.

Update:

I am scrapping data from page with help of JavaScript & displaying on fancy-box popup.

please help me on this


回答1:


Use a simple regex to solve it

str = str.replace(/\\/g, '')

Demo: Fiddle




回答2:


This is the answer according to the title as the title is "Remove all slashes in Javascript" not backslashes. So here is the code to remove all the slashes from a string in JavaScript.

str = '/mobiles-phones/.png';
str.replace(/\//g, "")//output would be "mobiles-phones.png";



回答3:


Regexs are great str.replace(/\\/g,'')




回答4:


How do I do string replace in JavaScript to convert ‘9.61’ to ‘9:61’?

var str = "one thing\\\'s for certain: power blackouts and surges can damage your equipment.";

str.replace("\", "");


来源:https://stackoverflow.com/questions/16171320/remove-all-backslashes-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!