function for split a complex string
-
hi to all i have a string with this format x=numbery=datez=number... for example of this string can be : x=123y=2013/02/01z=12345p=111 i want a function that get me this x=123 y=2013/02/01 z=12345 p=111 how can i do this? note to this point that my string can not be change and add extra character to this string thanks in advance
-
hi to all i have a string with this format x=numbery=datez=number... for example of this string can be : x=123y=2013/02/01z=12345p=111 i want a function that get me this x=123 y=2013/02/01 z=12345 p=111 how can i do this? note to this point that my string can not be change and add extra character to this string thanks in advance
There is usually many ways to do string manipulation but one way would be to split on the = and then you'll have the rightmost character to be the starting of your next string. You'll have to put in a case for the first one. Or, just loop through each character and process.
There are only 10 types of people in the world, those who understand binary and those who don't.
-
hi to all i have a string with this format x=numbery=datez=number... for example of this string can be : x=123y=2013/02/01z=12345p=111 i want a function that get me this x=123 y=2013/02/01 z=12345 p=111 how can i do this? note to this point that my string can not be change and add extra character to this string thanks in advance
you have to define what are the valid characters that can be on the left hand side of the '=' sign. in other words can you have something like the following? pa1n=1234h1nd=4321gr33d=6789 pa1n=1234 h1nd=4321 gr33d=6789 that gets a lot more difficult vs if you only allow stuff on the left to be alpha characters and then stuff on the right to be numeric and special characters. sounds like a homework question from a programming class.
as if the facebook, twitter and message boards weren't enough - blogged
-
hi to all i have a string with this format x=numbery=datez=number... for example of this string can be : x=123y=2013/02/01z=12345p=111 i want a function that get me this x=123 y=2013/02/01 z=12345 p=111 how can i do this? note to this point that my string can not be change and add extra character to this string thanks in advance
function splitString(myStr) {
var regex = new RegExp(/[a-z]+[0-9]*[a-z]*=/ig);
var keyPairs = myStr.match(regex).join('').split('=');
var valuePairs = myStr.split(regex);
document.write('======== Start ==========
');
document.write('INPUT: ** ' + myStr + '**
');var map = {}; for(var i = 0; i < keyPairs.length - 1; i++) { map\[keyPairs\[i\]\] = valuePairs\[i+1\]; } for(key in map) { document.write(key + ' = ' + map\[key\] + '
');
}
document.write('======== End ==========');
}splitString('x=123y=2013/02/01z=12345p=111');
splitString('pa1n=1234h1nd=4321gr33d=6789');Thanks & Regards, Niral Soni