views:

65

answers:

3

I have a string in a variable

ie;

var test= "http://www.gmail.com@%@http://www.google.com@%@http://www.yahoo.com@%@";

i have this thing in my javascript function.

i want to split this string from the occurences of the special characters

ie: @%@

so after splitting

i want to push this thing to an array

like this

var spcds = [];
    spcds.push("http://www.gmail.com");
 spcds.push("http://www.google.com");
 spcds.push("http://www.yahoo.com");

what i need is just split the string variable

and push that to spcds array.

how can i do this in my js function.

so the resultant values will have to store to another variable which i have to push to the array spcds.

+1  A: 

Hi, This will give you an array of the strings you are after Then you can just iterate through the array as needed.

var mySplitResult = myString.split("@%@");
Leigh Shayler
+1  A: 

this should give you the array you want:

var testarray= 
    ("http://www.gmail.com@%@http://www.google.com@%@http://www.yahoo.com@%@")
     .split('@%@');
KooiInc
+3  A: 

Use the split method to split the string:

var parts = test.split("@%@");

And if you don’t want to have empty parts, use the filter method to filter out the values that are not an empty string:

var parts = test.split("@%@").filter(function(val){return val!="";});
Gumbo