Reputation: 993
I try to split a string to send it to arraycollection. The problem is that each record contain several field. With one field, I found how to do but in my case, no.
var str:String="12/12/2008-70,15#05/03/2005-193,50#23/04/1987-45,23";
public function splitDouble(stringInit:String,sep1:String):ArrayCollection{
var tempAc:ArrayCollection= new ArrayCollection((stringInit.split(sep1)));
return tempAc;
}
}
Record delimiter is '#', field delimiter is ','. I'd like to add something like that: tempAc[0][0]==12/12/2008; tempAc[0][1]==70,15;
Thanks
So, can you help me to solve that?
Thanks
Upvotes: 1
Views: 1384
Reputation: 51837
Nearly there, try something like this:
public function splitDouble(source:String,rSeparator:String,fSeparator:String):ArrayCollection{
var records:Array = source.split(rSeparator);
var result:Array = [];
for (var i : int = 0; i < records.length; i++) {
result[i] = records[i].split(fSeparator);
}
return new ArrayCollection(result);
}
For brevity you could use the every() function, but I think it's simpler/cleaner without an anonymous function or something like that.
Upvotes: 2