hi all,
I have a string build up like varstring1_varstring2_id1_id2 eg: move_user_12_2 .
I want to extract id1 and id2 out of the string. Since I'm a complete prototype beginner I'm having some troubles solving this.
Thanks Stijn
hi all,
I have a string build up like varstring1_varstring2_id1_id2 eg: move_user_12_2 .
I want to extract id1 and id2 out of the string. Since I'm a complete prototype beginner I'm having some troubles solving this.
Thanks Stijn
If by prototype you mean the prototype javascript framework, then what you need is the string.split method. So, in your case, the code would be something like
var myString = 'move_user_12_2';
var stringParts = myString.split('_');
var id1 = stringParts[2];
var id2 = stringParts[3];
You could probably just use the built-in string.split() operator
var s = "move_user_12_2".split('_');
var id1 = s[2], id2 = s[3];
A regular expression can also be handy
var str = "move_user_12_2";
var ids = str.match(/(\d+)/g);
alert(ids[0] + "\n" + ids[1]);