Learn creative coding writing simple programs
87. Playing with strings
We have been using numbers very often in our programs. This time we do some text manipulation. The data type used for text is called String. We discover how we can use the "+" character to join strings and test date and time functions like year(), month(), day(), hour(), minute() and second(). We create a small running clock and discover how to force a number to be printed always using two digits using the nf() function. nf() means "number format". To end the episode, we use a function called charAt(0) which returns one of the characters of a string (for example the first letter, or the third one), and another function called indexOf("t"), which tells us where in the string a certain letter is found. For example, find out where inside our string is the letter "t". Processing will return a number indicating the position, or -1 if the letter is not found.
Code editor
background
day
draw
frameRate
hour
minute
month
nf
println
second
setup
size
String
text
textSize
void
year
Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)
To indicate that a word in your comment is code, use the `backtick`. Example
Do `float` and `int` smell similar?
To highlight code blocks, surround it with ``` code-fences ``` like this:``` void setup() { size(600, 600); } ```