Working with Strings
When you are working with text, you might need to count the characters of a word or change all characters to uppercase. In this recipe, we are going to cover some functions that will come in use when working with text.
How to do it...
The first thing we'll do is declare some String variables and assign some values to them. Strings are basically a sequence of characters, placed between double quotes.
String word = "Hello"; String[] textArray; String wordList = "String,theory,is,confusing"; void setup() { textArray = new String[3]; textArray[0] = "Man"; textArray[1] = "Bear"; textArray[2] = "Pig"; noLoop(); }
Inside the draw()
function, we'll take a look at the methods we can use on our String variables.
println("Word: charAt(1): " + word.charAt(1) ); println("Word: length(): " + word.length() ); println("Word: substring( 2, 4 ): " + word.substring(2, 4) ); println("Word: toLowerCase(): " + word.toLowerCase() ); println("Word: toUpperCase(): " + word.toUpperCase...