Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

1 of 4
Jon Skeet
  • 1.5m
  • 894
  • 9.3k
  • 9.3k

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.)

Jon Skeet
  • 1.5m
  • 894
  • 9.3k
  • 9.3k

AltStyle によって変換されたページ (->オリジナル) /