Text 305
17 Text
“ I could entertain future historians by saying I think all this superstring stuff is crazy. ”
—Richard Feynman
In this chapter:
– Storing text in a String object.
– Basic String functionality.
– Creating and loading fonts.
– Displaying text.
17.1 Where do Strings come from?
In Chapter 15, we explored a new object data type built into the Processing environment for dealing with
images—PImage. In this chapter, we will introduce another new data type, another class we get for free
with Processing , called String .
e String class is not a completely new concept. We have dealt with Strings before whenever we have
printed some text to the message window or loaded an image from a fi le.
println( "printing some text to the message window! "); // Printing a String
PImage img = loadImage("filename.jpg"); // Using a String for a file name
Nevertheless, although we have used a String here and there, we have yet to explore them fully and
unleash their potential. In order to understand the origins of the String , let’s remind ourselves where
classes come from. We know we can create our own classes (Zoog, Car, etc.). We can use classes built
into the Processing environment, such as PImage. And fi nally, in the last chapter we learned that we could
import additional Processing libraries to use certain classes such as Capture or Movie.
Nevertheless, these classes come from our lives in the Processing bubble. We have yet to venture out into
the great unknown, the world of thousands upon thousands of available Java classes. Before we leap over
the Java API cliff (which we will do in Chapter 23), it is useful to just peek over the edge and explore one
of the most basic and fundamental Java classes out there, the String class, which we will use to store and
manipulate text.
Where do we fi nd documentation for the String class?
In order to learn the details about built-in variables, functions, and classes, the Processing reference has
always been our guide. Although technically a Java class, because the String class is so commonly used,
Processing includes documentation in its reference. In addition, no import statement is required.
http://www.processing.org/reference/String.html