"
).
"This is a string."
The value of a string literal is an instance of the class
StringConstant
, which stores the string as a
sequence of UTF values, an optimized representation of 31-bit
Unicode/ISO 10646 values. Unicode allows ScriptX to represent
most international characters.Strings can contain any characters, including single quotes, operators, and other characters that would be interpreted differently by ScriptX outside the string. The following strings contain character sequences that make them look like other ScriptX constructs:
"Is it a string? Yes, it's a string."
"-- A string with a comment in it"
"a string with an assignment := in it"
"a string with arithmetic in it: 4 + 4"
Strings can also include end-of-line characters; that is, strings can be spread over several lines. End-of-line characters are preserved in a string as newline characters:
"Jack and Jill
went up the hill
to fetch a pail of water"
Table 2-1 lists special characters that can be included in strings as escape sequences.
Characters |
Meaning |
---|---|
\r
|
return
|
\n
|
new line
|
\t
|
tab
|
\"
|
double-quote
|
\\
|
backslash
|
\<nnnn>
|
hexadecimal values for Unicode characters
|
Note that ScriptX handles the problem of different
implementations of the newline character (\n) on different
platforms by forcing the newline character from all platforms
to the value 13.
"a string with a \n return in it"
"a string with a
return in it"
-- \<2122> represents the trademark symbol ( )
"ScriptX\<2122> is a really awesome language"
"ScriptX\<2122> is a really awesome language"
A Note on Strings and String
Constants
StringConstant
. Instances of
String
and StringConstant
appear the
same in most operations, but functions or operators (such as
the comparison functions described on page 40) that are concerned with the
classes of those objects may differentiate between them.
When you attempt to modify a string constant, some operations
convert it automatically to a String
object, its
editable counterpart. These operations include string addition
and subtraction, described on page
43. Other operations require that you explicitly coerce
the string constant to a string. Coercion of objects from one
class to another is described in Chapter 3, "Working with Objects."
This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.