Link to home
Start Free TrialLog in
Avatar of Plucka
PluckaFlag for Australia

asked on

Looping Over a List

Hi,

I have a comma delimited list, how do I loop over it. It's being passed into a function

ie

x = functionName('one,two,three,four,five');

I see there is a List data type and also thought of doing this by converting it to an array.
ASKER CERTIFIED SOLUTION
Avatar of Aneesh Chopra
Aneesh Chopra
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ch2
ch2

There are classes to read the whole csv file.
I copy pasted from a class i have. The above should work, but this is just for a tip.

var csvfile:LoadVars;
var linesep:String;
var lines:Array;
var linelen:Number;
var line:String;
var record:Array;
var recsep:String;
var recval:Number;
//
csvfile = new LoadVars();
csvfile.load("customers.csv");
//
csvfile.onData = function(csv:String) {
      linesep = chr(13)+chr(10);
      lines = csv.split(linesep);
      linelen = lines.length;
      line = '';
      //
      recsep = chr(44);
      //
      record = new Array();
      for (var i:Number = 0; i<linelen; i++) {
            //
            line = lines[i];
            record[i] = line.split(chr(44));
            //
            recval = record[i].length-1;
            // Trace first value from each record
            trace(record[i][0]);
      }
};