Simple text parse question
in
Programming Questions
•
1 year ago
Hello, I am learning processing and working on a school project. I am having some trouble understanding text parsing and arrays. I can parse a .tsv and create a single Array, but how do I split the array every time there is a blank line in the .tsv? I have quite a few files that I would like to combine and pass into the constructor once, rather than running each file through this individually.
I found this snippet of code that I am using to parse .tsv's into an Array:
public Table2(PApplet p5, String filename) {
String[] rows = p5.loadStrings(filename);
data = new String[rows.length][];
for (int i = 0; i < rows.length; i++) {
if (PApplet.trim(rows[i]).length() == 0) continue;
if (rows[i].startsWith("#")) continue;
String[] pieces = PApplet.split(rows[i], PApplet.TAB);
data[rowCount] = pieces;
rowCount++;
}
data = (String[][]) PApplet.subset(data, 0, rowCount);
}
Is it possible to make an array of arrays? I was thinking of wrapping all of this inside of a "for" loop that splits at the "/n" symbol (kind of like the line that ends in PApplet.TAB) Unfortunately, all of my tutorial resources have left me with a lot of questions about iteration and arrays :/
Thanks in advance,
Voo
I found this snippet of code that I am using to parse .tsv's into an Array:
public Table2(PApplet p5, String filename) {
String[] rows = p5.loadStrings(filename);
data = new String[rows.length][];
for (int i = 0; i < rows.length; i++) {
if (PApplet.trim(rows[i]).length() == 0) continue;
if (rows[i].startsWith("#")) continue;
String[] pieces = PApplet.split(rows[i], PApplet.TAB);
data[rowCount] = pieces;
rowCount++;
}
data = (String[][]) PApplet.subset(data, 0, rowCount);
}
Is it possible to make an array of arrays? I was thinking of wrapping all of this inside of a "for" loop that splits at the "/n" symbol (kind of like the line that ends in PApplet.TAB) Unfortunately, all of my tutorial resources have left me with a lot of questions about iteration and arrays :/
Thanks in advance,
Voo
1