Click here to Skip to main content
15,886,049 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi guys,

I have an asp.net website,

in my jquery code, i'm replacing this

getData = "{~Ref~:~" + sp[0] + "~,~Reference~:~" + sp[1] + "~,~Description~:~" + sp[2] + "~,~Quantity~:~" + sp[3] + "~,~Unit~:~" + sp[4] + "~,~UnitPrice~:~" + sp[5] + "~,~TotalPrice~:~" + sp[6] + "~},";


////alert(getData);

var fullData = "[" + getData.replace(/'/g, '\"').replace('~', '"') + "]";


and replace in 'fulldata', is not actually replacing all '~' with single quotes
but its replacing the ever first '~' only.

can any one please help me.


Thanks
Posted
Updated 7-Jun-15 19:48pm
v2

1 solution

You need to use a regular expression with the "global" flag set as the first parameter - just as you did for the first replace call:
JavaScript
var fullData = "[" + getData.replace(/'/g, '\"').replace(/~/g, '"') + "]";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900