Go to the first, previous, next, last section, table of contents.


String Type

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 on its own (not inside a string). 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.

The printed representation of a string consists of a double-quote, the characters it contains, and another double-quote. However, you must escape any backslash or double-quote characters in the string with a backslash, like this: "this \" is an embedded quote".

The newline character is not special in the read syntax for strings; if you write a new line between the double-quotes, it becomes a character in the string. 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 while reading a string.

"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."

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 consists of zero or more elements, in groups of three as follows:

beg end plist

The elements beg and end are integers, and together specify a range of indices in the string; plist is the property list for that range.

See section Strings and Characters, for functions that work on strings.


Go to the first, previous, next, last section, table of contents.