Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
dimitarsp
dimitarsp's Profile
1
Posts
0
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
Parsing data from a CSV
[1 Reply]
05-Nov-2012 11:49 AM
Forum:
Programming Questions
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 match
String[] _rowName = table.data[integer]; // get data to fill
//get first variables
for (int i = 0; i<_rowName.length; i++) { //iterate over
ArrayList tempMin = new ArrayList();
if (trim(_rowNameMaj[i]).length() != 0) {
dMaj.add(_rowNameMaj[i]);
}
}
//place maj values from arraylist into an array
String[] _bMaj = (String[]) dMaj.toArray(new String[0]);
bMaj = _bMaj; //set value to global variable
//min values
ArrayList bigOne = new ArrayList(); //arraylist of an arraylist
int count = 0;
for (int i = 0; i<_rowName.length; i++) { //iterate over
ArrayList tempMin = new ArrayList(); //temp arraylist to collect all items until count is reset
if (trim(_rowNameMaj[i]).length() != 0) { //check if box is not empty & set count to 0
count = 0;
tempMin.add(_rowName[i]);
count++;
}
else if (trim(_rowNameMaj[i]).length() == 0) { //if next box is empty, add to count
count++;
tempMin.add(_rowName[i]);
}
// below are attempts to fill bMin, but none of them work
minimums = 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 work
for (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 matrix
data = new String[rows.length][columns.
length];
// add column pieces into data matrix
for (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];
}
}
}
}
«Prev
Next »
Moderate user : dimitarsp
Forum