O'Reilly logo

ActionScript 3.0 Bible by Roger Braunstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 6. Text, Strings, and Characters

FEATURED CLASS

  • String

Text in ActionScript is represented as a string, as in "the book consisted entirely of a long string of incomprehensible characters." A string can be any piece of textual data from a single letter to a word to the entirety of Wikipedia. Strings don't have to contain legible prose: they might also contain or be exclusively made of numbers or symbols. Strings can also handle multiple languages. Strings are an essential building block of virtually all programs, so ActionScript 3.0 provides several methods for working with, manipulating, searching, and converting strings.

Working with String Literals

Of course, because they're so indispensable, you've already been exposed to strings before this chapter. Most of what you've seen so far has been string literals — pieces of text surrounded by quotation marks added directly into the code. But as you learned in Chapter 2, "ActionScript 3.0 Language Basics," everything in ActionScript 3.0 is an object, including strings. When you type a string like "Hello, world!" you're actually creating an instance of the String class. The String class offers a load of extra functionality beyond the capability to store text.

Tip

Although technically there is a difference between a string created with a new String() statement and a string created using a string literal, the compiler converts string literals into string objects automatically. Therefore, the following code is perfectly valid:

"banana".length; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required