Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a variable having value like this
JavaScript
var strFileTypeGroup="
var GroupArr = new Array();GroupArr[0] = '19~3';GroupArr[1] = '19~4';GroupArr[2] = '20~5';GroupArr[3] = '20~6';GroupArr[4] = '18~8';GroupArr[5] = '20~9';GroupArr[6] = '19~10';GroupArr[7] = '19~11';GroupArr[8] = '17~12';GroupArr[9] = '19~13';GroupArr[10] = '20~14';GroupArr[11] = '19~15';GroupArr[12] = '18~16';GroupArr[13] = '18~17';GroupArr[14] = '17~21';GroupArr[15] = '20~22';GroupArr[16] = '20~16';GroupArr[17] = '8~28';GroupArr[18] = '15~28';GroupArr[19] = '0~31';GroupArr[20] = '0~32';GroupArr[21] = '0~33';GroupArr[22] = '19~23';GroupArr[23] = '0~41';GroupArr[24] = '1~2';GroupArr[25] = '0~42';GroupArr[26] = '2~5';GroupArr[27] = '6~1';GroupArr[28] = '4~1';GroupArr[29] = '0~43';GroupArr[30] = '0~44';"


I want to output in a variable like this
JavaScript
var x="19~3,19~4,20~5,20~6,18~8,20~9,19~10,19~11,17~12,19~13,20~14,19~15,18~16,18~17,17~21,20~22,20~16,8~28,15~28,0~31,0~32,0~33,19~23,0~41,1~2,0~42,2~5,6~1,4~1,0~43,0~44";


In javascript.

Thanks & Regards
Mohammad Wasif
Posted
v2
Comments
What have you tried and where is the problem?
Karthik_Mahalingam 6-Jan-14 9:38am    
oh.. i wil rephrase my answer soon..

1 solution

try this code..

JavaScript
var match, result = "", regex = /'(.*?)'/ig;
           while (match = regex.exec( strFileTypeGroup  )) {
               result += match[1] + ',';
           }

result = result.substring(0, result.length - 1); //trimming , at the end


           alert(result);
 
Share this answer
 
v5

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