Quantcast
Channel: Adobe Community : Popular Discussions - InDesign Scripting
Viewing all articles
Browse latest Browse all 15932

Removing unwanted characters from imported string

$
0
0

Hello,

I have a tab-delimited .txt file which I have to import into Indesign for further processing.

The file is composed by a 3 columns header row at the beginning (Code, Description, price) followed by a series of 3 columns data rows.

The problem is that sometimes, depending on the way the txt/csv file has been created, may include unwanted characters (such as spaces, double spaces, etc.).

Is there a way to "clean" the imported strings from these unwanted characters?

 

This is my starting code:

 

 

function processImportedTxt(){

    //Open .csv file

    var csvFile = File.openDialog("Open file .csv","tab-delimited(*.csv):*.csv;");

    datafile = new File(csvFile);

    if (datafile.exists){

        datafile.open('r');

   };

   var csvData = new Array();

   while(!datafile.eof){//read every row till the end of file

        csvData.push(datafile.readln());

   }

    datafile.close();

 

    for(a=1; a<csvData.length; a++){

       

        var myRowData = csvData[a];//row of data

        var mySplitData = myRowData.toString().split("\t");//divide columns

        var myRowCode = mySplitData[0];

        var myRowDesc = mySplitData[1];

        var myRowPrice = mySplitData[2];

       

        // Here goes code for cleaning strings from unwanted characters

       

    }

}

 

processImportedTxt();

 

Any help would be much appreciated

Thanks in advance


Viewing all articles
Browse latest Browse all 15932

Trending Articles