PDA

View Full Version : return an object from a string


mrhoo
05-19-2006, 05:48 PM
reSplit is used to return an object from
a string of name/value pairs.

pass reSplit()your own delimeters or use the defaults.


String.prototype.reSplit= function(d1,d2){
if(!d1) d1= /\s*;\s*/
if(!d2) d2= /\s*\=/;
var Obj= new Object, tem;
var A= this.split(d1);
var L= A.length;
for(var i= 0; i< L; i++){
if(!A[i]) continue;
tem= A[i].splat(d2);
Obj[tem[0]]=tem[1];
}
return Obj;
};
String.prototype.splat= function(delim){
var ax,L;
var d= this.match(delim);
if(!d) return this;
else{
ax= d.index;
L= d[0].length;
return [this.substring(0,ax), this.substring(ax+L), d[0]];
}
};

Kor
06-05-2006, 03:13 PM
Can u detail a little bit what this function suppose to do?