简体   繁体   English

如何删除Javascript字符串中所有出现的字符'?

[英]How to remove all occurrence of character ' in a string in Javascript?

My string is like (passenger's name is Suraj and passenger's contact number is XXXXXXX672 ). 我的字符串就像(乘客的名字是Suraj,乘客的联系电话是XXXXXXX672 )。 How can I remove the occurrences of ' from the string ? 如何从字符串中删除出现的'? I tried using 我尝试使用

comments = comments.replace(/'/g, ' '); and comments = comments.replace(/\'/g, ' ');

But they did not work. 但是他们没有用。 Please suggest me the needful. 请建议我有需要。

Your code 您的密码

var temp = "passenger's name is Suraj and passenger's contact number is    XXXXXXX672";
var test = temp.replace(/'/g, ' ');

Output 产量

"passenger s name is Suraj and passenger s contact number is XXXXXXX672"

Its working fine. 它的工作正常。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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