I have this string 'john smith~123 Street~Apt 4~New York~NY~12345'
Using javascript what is the fastest way to parse this into
var name = "john smith"; var street= "123 Street";
etc
I have this string 'john smith~123 Street~Apt 4~New York~NY~12345'
Using javascript what is the fastest way to parse this into
var name = "john smith"; var street= "123 Street";
etc
With simple JavaScript:
var split = 'john smith~123 Street~Apt 4~New York~NY~12345'.split('~');
var name = split[0];
var street = split[1];
etc...
You'll want to look into JavaScript's substr or split as this is not really a task suited for jQuery
You don't need jQuery.
var s = 'john smith~123 Street~Apt 4~New York~NY~12345';
var fields = s.split(/~/);
var name = fields[0];
var street = fields[1];
well, easiest way would be something like:
var address = theEncodedString.split(/~/)
var name = address[0], street = address[1]
Something like:
var divided = str.split("/~/");
var name=divided[0];
var street = divided[1];
Is probably going to be easiest