Hello,
I have a csv list which appears like this:
00001;Product_1
00001;Product_2
00002;Product_3
I'm trying to assemble a script that will generate a Multi-dimensional Array from this csv file. I found something in PS-Script forum which, in part, suits my needs ("Compare filenames in a csv to files in a directory") and tried to modify it.
//---< Create Multi-Dimensional Array from CSV list >---
function main() {
//Ask the user to select the comma-delimited file
var csvFile = File.openDialog("Open Comma-delimited File","comma-delimited(*.csv):*.csv;");
//Make sure the comma-delimited file exists and then open it
datafile = new File(csvFile);
if (datafile.exists){
datafile.open('r');
};
var myRelazioni = new Array();
while(!datafile.eof){//read each line to end of file
myRelazioni.push(new Array(datafile.readln()));
}
datafile.close();
}
main();
This way I can get an Array which looks like this:
myRelazioni = [["00001;Product_1"],["00001;Product_2"],["00002;Product_3"]]
The question is that I want to obtain an Array which instead looks like this:
myRelazioni = [["00001;Product_1","00001;Product_2"],["00002;Product_3"]]
that is, I want to find a rule to group together those lines which start with the same set of characters into the same sub-array ("00001" in this case, but could be any set of characters).
Any suggestion would be much appreciated
Thanks
