Ladle
Junior Member
Offline
Posts: 91
Re: Substrings..?
Reply #5 - Oct 13th , 2009, 2:57pm
Hmm, still no, could it be a factor that some of the strings start with a 0? eg 0123..i thought that woulnt matter with strings rather than integers.. my whole code is here( the table class is pasted at the end because i was having trouble making it work another way: PImage blueImage; Table dataTable; int rowCount; void setup(){ size (200, 181); blueImage = loadImage("blueImage.png"); dataTable = new Table("testnums.txt"); rowCount = dataTable.getRowCount(); } void draw() { background(255); image(blueImage, 0, 0); smooth(); fill(192,0,0); noStroke(); for(int row = 1; row < rowCount; row++) { String time = dataTable.getString(row, 0); // column 1. String daytime = dataTable.getString(row, 1); // column 2. String kind = dataTable.getString(row, 2);//column3. String hourx = time.substring(2,4); // ellipse(x, y, 9, 9); //textFont("Helvetica.dfont", 32); //fill(51); //text("time"); println(time); println(daytime); println(kind); println(hourx); } } class Table { String[][] data; int rowCount; Table() { data = new String[10][10]; } Table(String filename) { String[] rows = loadStrings(filename); data = new String[rows.length][]; for (int i = 0; i < rows.length; i++) { if (trim(rows[i]).length() == 0) { continue; // skip empty rows } if (rows[i].startsWith("#")) { continue; // skip comment lines } // split the row on the tabs String[] pieces = split(rows[i], TAB); // copy to the table array data[rowCount] = pieces; rowCount++; // this could be done in one fell swoop via: //data[rowCount++] = split(rows[i], TAB); } // resize the 'data' array as necessary data = (String[][]) subset(data, 0, rowCount); } int getRowCount() { return rowCount; } // find a row by its name, returns -1 if no row found int getRowIndex(String name) { for (int i = 0; i < rowCount; i++) { if (data[i][0].equals(name)) { return i; } } println("No row named '" + name + "' was found"); return -1; } String getRowName(int row) { return getString(row, 0); } String getString(int rowIndex, int column) { return data[rowIndex][column]; } String getString(String rowName, int column) { return getString(getRowIndex(rowName), column); } int getInt(String rowName, int column) { return parseInt(getString(rowName, column)); } int getInt(int rowIndex, int column) { return parseInt(getString(rowIndex, column)); } float getFloat(String rowName, int column) { return parseFloat(getString(rowName, column)); } float getFloat(int rowIndex, int column) { return parseFloat(getString(rowIndex, column)); } void setRowName(int row, String what) { data[row][0] = what; } void setString(int rowIndex, int column, String what) { data[rowIndex][column] = what; } void setString(String rowName, int column, String what) { int rowIndex = getRowIndex(rowName); data[rowIndex][column] = what; } void setInt(int rowIndex, int column, int what) { data[rowIndex][column] = str(what); } void setInt(String rowName, int column, int what) { int rowIndex = getRowIndex(rowName); data[rowIndex][column] = str(what); } void setFloat(int rowIndex, int column, float what) { data[rowIndex][column] = str(what); } void setFloat(String rowName, int column, float what) { int rowIndex = getRowIndex(rowName); data[rowIndex][column] = str(what); } // Write this table as a TSV file void write(PrintWriter writer) { for (int i = 0; i < rowCount; i++) { for (int j = 0; j < data[i].length; j++) { if (j != 0) { writer.print(TAB); } if (data[i][j] != null) { writer.print(data[i][j]); } } writer.println(); } writer.flush(); } }