• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 364
  • Last Modified:

Repace single quote to double quote

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
0
mousemat24
Asked:
mousemat24
  • 4
  • 3
1 Solution
 
erikTsomikSystem Architect, CF programmer Commented:
0
 
zstapicCommented:
Hello,

use replace function


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

Open in new window

0
 
mousemat24Author 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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mousemat24Author Commented:
I tried

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

and it dosnt work?
0
 
zstapicCommented:
this is correct

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

Open in new window

0
 
mousemat24Author 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
0
 
zstapicCommented:
:) ok, is this what you are looking for?

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

Open in new window

0
 
mousemat24Author Commented:
We got there :-)

Thanks zstapic for your help
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now