Parsing data from a CSV
in
Programming Questions
•
11 months ago
Hello,
I have data from a CSV format that looks like this:
a,,,b,
36,28,90,5,24
what would be the best way to either have something like
myStringArray = [a, [36,28,90]], [b, [5,24]]
or
myStringArray1 = {a,b}; // this part i can do
myStringArray2 = {{36,28,90}, {5,24}};
many thanks,
Dimitar
here is my attempt at a parsing class:
-
class dParse {
String[] bMaj;String[][] bMin;
dParse() {}
void getList(int integer) {
ArrayList dMaj = new ArrayList();ArrayList dMin = new ArrayList();
String[][] minimums;
String[] _rowNameMaj = table.data[0]; //get data first to matchString[] _rowName = table.data[integer]; // get data to fill
//get first variablesfor (int i = 0; i<_rowName.length; i++) { //iterate overArrayList tempMin = new ArrayList();if (trim(_rowNameMaj[i]).length() != 0) {dMaj.add(_rowNameMaj[i]);}}
//place maj values from arraylist into an arrayString[] _bMaj = (String[]) dMaj.toArray(new String[0]);bMaj = _bMaj; //set value to global variable
//min valuesArrayList bigOne = new ArrayList(); //arraylist of an arraylistint count = 0;for (int i = 0; i<_rowName.length; i++) { //iterate overArrayList tempMin = new ArrayList(); //temp arraylist to collect all items until count is resetif (trim(_rowNameMaj[i]).length() != 0) { //check if box is not empty & set count to 0count = 0;tempMin.add(_rowName[i]);count++;}else if (trim(_rowNameMaj[i]).length() == 0) { //if next box is empty, add to countcount++;tempMin.add(_rowName[i]);}
// below are attempts to fill bMin, but none of them workminimums = new String[_bMaj.length][];
//place min values from arraylist into an array//String[] temp_bMin = (String[]) tempMin.toArray(new String[0]);//fl[] = append((new String(temp_bMin)), fl); //this line does not workfor (int n = 0; n< bMaj.length; n++ ) {count[n] = (String[]) toArray(new String[0]);}tempMin.clear(); //clear temporaryList}}
String[] getMaj() {return bMaj;}
String[][] getMin() {return bMin;}}
here is my current import class:
-
class dTable {
int rowCount;int columnCount;String[][] data;String filename;
dTable(String _filename) {filename = _filename;}
void load() {String[] rows = loadStrings(filename);String[] columns = split(rows[0], ',');rowCount = rows.length;columnCount = columns.length;
//set the size of the matrixdata = new String[rows.length][columns.length];
// add column pieces into data matrixfor (int i = 0; i < rows.length; i++) {String[] colEntries = split(rows[i], ',');for (int j = 0; j < columns.length; j++) {data[i][j] = colEntries[j];}}}}
1