String

A string is the basic text datatype. It has the MacRoman encoding; see "Unicode Text," later in this chapter, for more about the implications of this. Strings are your primary medium for communicating text information to a scriptable application. AppleScript provides some basic string operators (discussed in Chapter 15).

A literal string is delimited by quotation marks:

set s to "howdy"
class of s -- string

The empty string is symbolized by "".

In typing a string literal, you may enter certain characters in "escaped " form; they are listed in Table 13-1. These are the only "escaped" characters.

Table 13-1. "Escaped" string literals

What to type

ASCII equivalent

Result

\"

ASCII character 34

Quotation marks

\t

ASCII character 9

Tab

\r

ASCII character 13

Return

\n

ASCII character 10

Newline

\\

ASCII character 92

Backslash

Other untypeable characters may be generated using the ASCII character scripting addition command and incorporated into a string by concatenation (see chapters 15 and 21). There are also a few global properties expressing character values (listed in Chapter 16); these too can be incorporated into a string by concatenation.

After compilation, any tab, return, and newline characters within a literal string are unescaped and turned into whitespace ; they remain intact, but you can no longer see directly what characters they are, which is a pity (see "Lines" in Chapter 5). Script Debugger, however, can display such "invisibles."

Don't ...

Get AppleScript: The Definitive Guide, 2nd Edition 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.