From 5e660544d27b2eec9e133e44c9f10c0cf0a51664 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Mon, 6 Feb 2012 15:04:23 +0000 Subject: ready to load csv --- csvloader.pde | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 csvloader.pde (limited to 'csvloader.pde') 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); + } +} + -- cgit v1.2.3