Converting string into float from 2d array
in
Programming Questions
•
1 year ago
Hi I have been looking all around the web for hours trying to work out how to convert my data from a string into floats. the loading of all the data is working fine(its csv and is all numbers) but I cannot understand or find how to convert these strings I have loaded into floats so they may be used in my program. here is my code:
String [][] csv;
int csvWidth=0;
int dataWidth = 0;
void setup() {
size(200, 200);
String data[] = loadStrings("list.csv");
//calculate max width of csv file
for (int i=0; i < data.length; i++) {
String [] chars=split(data[i], ',');
if (chars.length>csvWidth) {
csvWidth=chars.length;
}
}
//create csv array based on # of rows and columns in csv file
csv = new String [data.length][csvWidth];
dataWidth =data.length;
//parse values into 2d array
for (int i=0; i < data.length; i++) {
String [] temp = new String [data.length];
temp= split(data[i], ',');
for (int j=0; j < temp.length; j++) {
csv[i][j]=temp[j];
}
}
}
void draw() {
background(255);
stroke(0);
for (int i = 0; i < dataWidth; i++) {
for (int j = 0; j < csvWidth; j++) {
println(csv[i][j]);
}
}
}
Help would be greatly appreciated, and this is also time sensitive, i would be over the moon if anyone could help
1