Removing unwanted characters from imported string
hello,
i have tab-delimited .txt file have import indesign further processing.
the file composed 3 columns header row @ beginning (code, description, price) followed series of 3 columns data rows.
the problem sometimes, depending on way txt/csv file has been created, may include unwanted characters (such spaces, double spaces, etc.).
is there way "clean" imported strings these unwanted characters?
this 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 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 cleaning strings unwanted characters
}
}
processimportedtxt();
any appreciated
thanks in advance
somestring.replace(/\s+/g,'') //\s = wildcart space (including tab)
More discussions in InDesign Scripting
adobe
Comments
Post a Comment