My string is like (passenger's name is Suraj and passenger's contact number is 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.
To remove all occurrences of a substring from a string, call the replaceAll() method on the string, passing it the substring as the first parameter and an empty string as the second. The replaceAll method will return a new string, where all occurrences of the substring are removed.
To replace all occurrences of a string in TypeScript, use the replace() method, passing it a regular expression with the g (global search) flag. For example, str. replace(/old/g, 'new') returns a new string where all occurrences of old are replaced with new .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With