Next: Arrays, Previous: Scalars, Up: Data Classes [Contents][Index]
A string
is a sequence of arbitrary characters. A string may
have any (nonnegative integer) length, and takes one byte of storage for
each character. A string is explicitly specified by enclosing the
characters of the string between single right-hand quotes or between
double quotes, like so:
'a string' "another string"
Such an explicit string specification is called a literal string. An empty literal string is specified by two single or double quotes, as follows:
'' ""
The kind of quote character that introduced the string is referred to as the active quote character. Within a string delimited by one kind of quotes, the inactive other kind is treated as a regular character. For example:
LUX>t,"It's wonderful!" It's wonderful! LUX>
If you insist on specifying an active quote character as explicit part of a literal string, then include a pair of such quote characters, as illustrated by the following example:
LUX>t,'It''s wonderful!' It's wonderful! LUX>
All C-style escape sequences are honored in literal strings. For
example, \n
inside a literal string is replaced by the newline
character. All such escape sequences start with a backslash \.
The recognized escape sequences are:
A newline character.
A horizontal tab character.
A vertical tab character.
A backspace character.
A carriage return character.
A form feed character.
A bell (audible alert) character.
A backslash (\) character.
A question mark (?) character.
A single quote (') character.
A double quote (") character.
The character indicated by the specified octal code (in place of the ooo) in the native character set of your computer. The octal number may have up to three characters: the greatest number up to three is taken that yields a valid octal number.
The character indicated by the specified hexadecimal code (in place of the hh) in the native character set of your computer. The hexadecimal number may have any number of hexadecimal digits. The greatest number is taken that yields a valid hexadecimal number, but you may get unexpected results if you specify more than two of them.
Internally, these escape sequences are replaced by a byte code that uniquely identifies them, just as happens to ordinary characters. O
most if not all computers, newline means "go to the start of the next line", carriage return means "go to the start of the current line", and backspace means "go one position closer to the start of the current line without deleting the current character". One can extract parts of a string by using subscripts (Subscripts).
Next: Arrays, Previous: Scalars, Up: Data Classes [Contents][Index]