Chapter 9. Strings

Introduction

Strings are the fundamental textual element of the ActionScript language. You should use strings for any data in your application that uses characters for any reason. For example:

myString = "this is a string";
myString = 'this is also a string';
myString = "strings can contain characters such as -(*+5~";

String values must always be enclosed within quotes. You can use either single or double quotes, but the starting and ending quotes enclosing a string must be of the same type.

// Both of these strings cause errors because of mismatched quotes.
myString = "an incorrect string';        // Ending quote should be double
myString = 'another incorrect string";   // Ending quote should be single

ActionScript provides functionality that allows you to work with strings in many ways. Although ActionScript does not provide native support for regular expressions (pattern matching), the third-party RegExp class described in Recipe 9.6 does.

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.