diff options
| author | Tim Redfern <tim@eclectronics.org> | 2012-02-06 15:04:23 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2012-02-06 15:04:23 +0000 |
| commit | 5e660544d27b2eec9e133e44c9f10c0cf0a51664 (patch) | |
| tree | dd09b097f2cb7f0d63a148ed3bb9f2110695b653 /csvloader.pde | |
| parent | 98a2dad141368b4d4f8efd2b6ef4dd2b4b1cb9bd (diff) | |
ready to load csv
Diffstat (limited to 'csvloader.pde')
| -rw-r--r-- | csvloader.pde | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/csvloader.pde b/csvloader.pde new file mode 100644 index 0000000..c8ba771 --- /dev/null +++ b/csvloader.pde @@ -0,0 +1,35 @@ +//for importing csv files into a 2d array +//thanks to che-wei wang + +class csvloader { + + String [][] data; + + csvloader(String file) { + + String lines[] = loadStrings(file); + int csvWidth=0; + + //calculate max width of csv file + for (int i=0; i < lines.length; i++) { + String [] chars=split(lines[i],','); + if (chars.length>csvWidth){ + csvWidth=chars.length; + } + } + + //create csv array based on # of rows and columns in csv file + data = new String [lines.length][csvWidth]; + + //parse values into 2d array + for (int i=0; i < lines.length; i++) { + String [] temp = new String [lines.length]; + temp= split(lines[i], ','); + for (int j=0; j < temp.length; j++){ + data[i][j]=temp[j]; + } + } + println("loaded "+file); + } +} + |
