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.

Tags: string, date, time, nf

Code editor

You can make changes to the code below. Then
Below you can ask and answer questions related to this video. If your question is unrelated to the video, please post it at the Processing Forum as I'm unable to help with all of your programs and still have enough free time to eat and sleep :)
comments powered by Disqus