Skip to main content
Inspiring
January 31, 2011
Question

CSV parser...

  • January 31, 2011
  • 1 reply
  • 503 views

Does anyone have some good CSV parsing code they could share?  I've got one that's been working fairly well, but now I need to also be able to parse embedded line breaks and the code I'm using handles the embedded breaks as new rows.

This topic has been closed for replies.

1 reply

Ten A
Community Expert
Community Expert
February 2, 2011

test this script.

var LF = String.fromCharCode(10);
var CR = String.fromCharCode(13);
var qrt = '"';
var dlmtr = '"' + ',' + '"';
var RET = qrt + LF + qrt;
var rslt = new Array();

var fNm = File.openDialog("select CSV file");
var f = new File(fNm);

if (f.open ('r')){
    var myCSV = f.read();
    f.close();
    myCSV = myCSV.substr(1,myCSV.length-2); //drop first and last quart
    var myRows = myCSV.split(RET); //only split real return code
    for (i=0;i<myRows.length;i++){
        var rslt = new Array();
        rslt = myRows.split(dlmtr);  //
        }
    }

You can access result data like


rslt[rows_num][cols_num]