We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Repace single quote to double quote

mousemat24
mousemat24 asked
on
Medium Priority
381 Views
Last Modified: 2012-06-27
Hi there

Wonder if you can help me?

I have a string like

test'asd

or

isnt'fdf'sdf

I need to change all single quotes to double quotes

so it should be like

test''asd

isnt''fdf''sdf

Thanks
Comment
Watch Question

erikTsomikSystem Architect, CF programmer

Commented:

Commented:
Hello,

use replace function


var str="test'asd";
str = str.replace("'","\"");

Open in new window

Author

Commented:
zstapic

Your version dosnt change ALL single quotes to two single quotes

i.e.

sss'aaa'uuu

should change too

sss''aaa''uuu

please not the replaced value are 2 single quotes

Thanks

Author

Commented:
I tried

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

and it dosnt work?

Commented:
this is correct

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

Open in new window

Author

Commented:
Hi zstapic

No this is still wrong, you code:

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

replaces the single quote to double quote, I need a single quote replaced with 2 single quotes.

Thanks
Commented:
:) ok, is this what you are looking for?

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

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
We got there :-)

Thanks zstapic for your help
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.