删除 Javascript 中的所有反斜杠

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16171320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 03:33:24  来源:igfitidea点击:

Remove all backslashes in Javascript

javascriptweb-scrapingslash

提问by user2046091

How to remove all backslash in a JavaScript string ?

如何删除 JavaScript 字符串中的所有反斜杠?

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.

我在 JavaScript 的帮助下从页面中抓取数据并在花式框弹出窗口中显示。

please help me on this

请帮我解决这个问题

回答by Arun P Johny

Use a simple regex to solve it

使用一个简单的正则表达式来解决它

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

Demo: Fiddle

演示:小提琴

回答by Safeer Ahmed

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.

这是根据标题的答案,因为标题是“删除 Javascript 中的所有斜杠而不是反斜杠。所以这是在 JavaScript 中从字符串中删除所有斜杠的代码。

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

回答by Mike

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

正则表达式很棒 str.replace(/\\/g,'')

回答by ismail atkurt

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

如何在 JavaScript 中进行字符串替换以将“9.61”转换为“9:61”?

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

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