Use:
str = str.replace(/[""]/g, '"');
str = str.replace(/[‘’]/g,"'");
or to do it in one statement:
str = str.replace(/[""]/g, '"').replace(/[‘’]/g,"'");
In JavaScript (as in many other languages) strings are immutable - string "replacement" methods actually just return the new string instead of modifying the string in place.
The MDN JavaScript reference entry for replace states:
Returns a new string with some or all matches of a pattern replaced by a replacement.
...
This method does not change the String object it is called on. It simply returns a new string.
Use:
str = str.replace(/[""]/g, '"');
str = str.replace(/[‘’]/g,"'");
or to do it in one statement:
str = str.replace(/[""]/g, '"').replace(/[‘’]/g,"'");
In JavaScript (as in many other languages) strings are immutable - string "replacement" methods actually just return the new string instead of modifying the string in place.
The MDN JavaScript reference entry for replace states:
Returns a new string with some or all matches of a pattern replaced by a replacement.
...
This method does not change the String object it is called on. It simply returns a new string.
Use:
str = str.replace(/[""]/g, '"');
str = str.replace(/[‘’]/g,"'");
or to do it in one statement:
str = str.replace(/[""]/g, '"').replace(/[‘’]/g,"'");
In JavaScript (as in many other languages) strings are immutable - string "replacement" methods actually just return the new string instead of modifying the string in place.
The MDN JavaScript reference entry for replace states:
Returns a new string with some or all matches of a pattern replaced by a replacement.
...
This method does not change the String object it is called on. It simply returns a new string.
- 670.9k
- 162
- 1k
- 1.5k
TryUse:
str = str.replace(/[""]/g, '"');
str = str.replace(/[‘’]/g,"'");
or to do it in one statement:
str = str.replace(/[""]/g, '"').replace(/[‘’]/g,"'");
I'm not aIn JavaScript expert, but(as in many other languages) strings are immutable - string "replacement" methods actually just return the new string instead of modifying the string in place. (Bizarrely enough, the few JavaScript string tutorials I've just looked up don't state a string's immutability - something I'd expect to be in the first or second paragraph of a C# or Java string tutorial.)
Confirmation comes fromThe the Mozilla Core JavaScript reference entryMDN JavaScript reference entry for replacereplace states:
Returns a new string with some or all matches of a pattern replaced by a replacement.
... ...
This method does not change the String object it is called on. It simply returns a new string.
Try:
str = str.replace(/[""]/g, '"');
str = str.replace(/[‘’]/g,"'");
or to do it in one statement:
str = str.replace(/[""]/g, '"').replace(/[‘’]/g,"'");
I'm not a JavaScript expert, but in many languages strings are immutable - string "replacement" methods actually just return the new string instead of modifying the string in place. (Bizarrely enough, the few JavaScript string tutorials I've just looked up don't state a string's immutability - something I'd expect to be in the first or second paragraph of a C# or Java string tutorial.)
Confirmation comes from the Mozilla Core JavaScript reference entry for replace:
Returns a new string with some or all matches of a pattern replaced by a replacement.
...
This method does not change the String object it is called on. It simply returns a new string.
Use:
str = str.replace(/[""]/g, '"');
str = str.replace(/[‘’]/g,"'");
or to do it in one statement:
str = str.replace(/[""]/g, '"').replace(/[‘’]/g,"'");
In JavaScript (as in many other languages) strings are immutable - string "replacement" methods actually just return the new string instead of modifying the string in place.
The MDN JavaScript reference entry for replace states:
Returns a new string with some or all matches of a pattern replaced by a replacement.
...
This method does not change the String object it is called on. It simply returns a new string.
Try:
str = str.replace(/[""]/g, '"');
str = str.replace(/[‘’]/g,"'");
or to do it in one statement:
str = str.replace(/[""]/g, '"').replace(/[‘’]/g,"'");
I'm not a JavaScript expert, but in many languages strings are immutable - string "replacement" methods actually just return the new string instead of modifying the string in place. (Bizarrely enough, the few JavaScript string tutorials I've just looked up don't state a string's immutability - something I'd expect to be in the first or second paragraph of a C# or Java string tutorial.)
Confirmation comes from the Mozilla Core JavaScript reference entry for replace:
Returns a new string with some or all matches of a pattern replaced by a replacement.
...
This method does not change the String object it is called on. It simply returns a new string.
Try:
str = str.replace(/[""]/g, '"');
str = str.replace(/[‘’]/g,"'");
or to do it in one statement:
str = str.replace(/[""]/g, '"').replace(/[‘’]/g,"'");
I'm not a JavaScript expert, but in many languages strings are immutable - string "replacement" methods actually just return the new string instead of modifying the string in place. (Bizarrely enough, the few JavaScript string tutorials I've just looked up don't state a string's immutability - something I'd expect to be in the first or second paragraph of a C# or Java string tutorial.)
Try:
str = str.replace(/[""]/g, '"');
str = str.replace(/[‘’]/g,"'");
or to do it in one statement:
str = str.replace(/[""]/g, '"').replace(/[‘’]/g,"'");
I'm not a JavaScript expert, but in many languages strings are immutable - string "replacement" methods actually just return the new string instead of modifying the string in place. (Bizarrely enough, the few JavaScript string tutorials I've just looked up don't state a string's immutability - something I'd expect to be in the first or second paragraph of a C# or Java string tutorial.)
Confirmation comes from the Mozilla Core JavaScript reference entry for replace:
Returns a new string with some or all matches of a pattern replaced by a replacement.
...
This method does not change the String object it is called on. It simply returns a new string.