tags:

views:

56

answers:

3

i want to replace " char to ' with javascript. thank you for your help. regards

+6  A: 

Use the replace method on the string str you want to replace it in:

str = str.replace(/"/g, "'");

Important is to use a regular expression with the g flag set to replace globally. If you omit that g flag or use a string for the search, you will only replace the first occurrence.

Gumbo
thank you very much.
Kerberos
@Kerberos: You’re welcome! And don’t forget to accept an answer (this does also apply to your other questions).
Gumbo
A: 
str.replace("\"", "\'")
Chris
That will only replace the first double quote.
Tim Down
I did not know he needed to do more then that. :-(
Chris
I don't know either, but it seems a reasonable assumption.
Tim Down
A: 

Use the replace method:

str = str.replace(/"/g, "'"));
Justin Ethier
Why the *i* flag? What is the uppercase/lowercase variant of `"`? ;-)
Gumbo
thank you very much.
Kerberos
@Gumbo - good point, thanks.
Justin Ethier