String s, t; void setup() { size(500, 440); smooth(); frameRate(1); noLoop(); s = "Hello World"; t = "Hello"; u = " Nation "; } // setup void draw() { background(#FFFFAA); // background color fill(#000000); // font (and other) color text("String s = " + s, 20, 80); text("String t = " + t, 20, 100); text("String u = '" + u + "' Note: (includes the blanks between the ' ')", 20, 120); text("s.charAt(6) = " + s.charAt(6), 20, 160); text("s.charCodeAt(6) = " + s.charCodeAt(6), 200, 160); text("s.equals(t) = " + s.equals(t), 20, 180); text("t.equals(\"Hello\") = " + t.equals("Hello"), 200, 180); text("s.indexOf(\"o\") = " + s.indexOf("o"), 20, 200); text("s.lastIndexOf(\"o\") = " + s.lastIndexOf("o"), 200, 200); text("s.indexOf(\"Hello\", 0) = " + s.indexOf("Hello", 0), 20, 220); text("s.indexOf(\"Hello\", 1) = " + s.indexOf("Hello", 1), 200, 220); text("s.search(\"Hello\") = " + s.search("Hello"), 20, 240); text("s.search(\"World\") = " + s.search("World"), 200, 240); text("s.toLowerCase() = " + s.toLowerCase(), 20, 260); text("s.toUpperCase() = "+ s.toUpperCase(), 200, 260); text("s.length() = " + s.length(), 20, 280); text("u.length() = " + u.length(), 200, 280); text("u.trim() = " + u.trim(), 20, 300); text("u.trim().length() = " + u.trim().length(), 200, 300); text("s.substring(6) = " + s.substring(6), 20, 320); text("s.substring(6, 9) = " + s.substring(6,9), 200, 320); text("s.substr(6) = " + s.substr(6), 20, 340); text("s.substr(6, 3) = " + s.substr(6,3), 200, 340); text("s.slice(6) = " + s.slice(6), 20, 360); text("s.slice(6, 9) = " + s.slice(6, 9), 200, 360); text("s.slice(-3) = " + s.slice(-3), 20, 380); text("s.replace(\"Hello\", \"Goodbye\") = " + s.replace("Hello", "Goodbye"), 20, 420); text("s.replace(/o/g, \"OOO\" = " + s.replace(/o/g, "000"), 20, 400); fill(#FF0000); text("Testing Javascript String Functions", 20, 20); text("in Processing", 20,40); } // draw