• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CSV parser...

Engaged ,
Jan 31, 2011 Jan 31, 2011

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

450

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Feb 02, 2011 Feb 02, 2011

Copy link to clipboard

Copied

LATEST

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]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines