Go to the previous, next section.
A string is an array of characters. Strings are used for many purposes in Emacs, as can be expected in a text editor; for example, as the names of Lisp symbols, as messages for the user, and to represent text extracted from buffers. Strings in Lisp are constants; evaluation of a string returns the same string.
The read syntax for strings is a double-quote, an arbitrary number of
characters, and another double-quote, "like this". The Lisp
reader accepts the same formats for reading the characters of a string
as it does for reading single characters (without the question mark that
begins a character literal). You can enter a nonprinting character such
as tab, C-a or M-C-A using the convenient escape sequences,
like this: "\t, \C-a, \M-\C-a". You can include a double-quote
in a string by preceding it with a backslash; thus, "\"" is a
string containing just a single double-quote character.
(See section Character Type, for a description of the read syntax for
characters.)
If you use the `\M-' syntax to indicate a meta character in a string constant, this sets the 2**7 bit of the character in the string. This is not the same representation that the meta modifier has in a character regarded as a simple integer. See section Character Type.
Strings cannot hold characters that have the hyper, super or alt modifiers; they can hold ASCII control characters, but no others. They do not distinguish case in ASCII control characters.
In contrast with the C programming language, Emacs Lisp allows newlines in string literals. But an escaped newline--one that is preceded by `\'---does not become part of the string; i.e., the Lisp reader ignores an escaped newline in a string literal.
"It is useful to include newlines
in documentation strings,
but the newline is \
ignored if escaped."
=> "It is useful to include newlines
in documentation strings,
but the newline is ignored if escaped."
The printed representation of a string consists of a double-quote, the
characters it contains, and another double-quote. However, any
backslash or double-quote characters in the string are preceded with a
backslash like this: "this \" is an embedded quote".
A string can hold properties of the text it contains, in addition to the characters themselves. This enables programs that copy text between strings and buffers to preserve the properties with no special effort. See section Text Properties. Strings with text properties have a special read and print syntax:
#("characters" property-data...)
where property-data is zero or more elements in groups of three as follows:
beg end plist
The elements beg and end are integers, and together specify a portion of the string; plist is the property list for that portion.
See section Strings and Characters, for functions that work on strings.
Go to the previous, next section.