Next: , Previous: , Up: Strings and Characters   [Contents][Index]


10.1 String and Character Basics

Strings in SXEmacs Lisp are arrays that contain an ordered sequence of characters. Characters are their own primitive object type in SXEmacs since XEmacs 20.

However, in XEmacs 19, characters are represented in XEmacs Lisp as integers; whether an integer was intended as a character or not is determined only by how it is used. See Character Type.

The length of a string (like any array) is fixed and independent of the string contents, and cannot be altered. Strings in Lisp are not terminated by a distinguished character code. (By contrast, strings in C are terminated by a character with ASCII code 0.) This means that any character, including the null character (ASCII code 0), is a valid element of a string.

Since strings are considered arrays, you can operate on them with the general array functions. (See Sequences Arrays Vectors.) For example, you can access or change individual characters in a string using the functions aref and aset (see Array Functions).

Strings use an efficient representation for storing the characters in them, and thus take up much less memory than a vector of the same length.

Sometimes you will see strings used to hold key sequences. This exists for backward compatibility with Emacs 18, but should not be used in new code, since many key chords can’t be represented at all and others (in particular meta key chords) are confused with accented characters.

Strings are useful for holding regular expressions. You can also match regular expressions against strings (see Regexp Search). The functions match-string (see Simple Match Data) and replace-match (see Replacing Match) are useful for decomposing and modifying strings based on regular expression matching.

Like a buffer, a string can contain extents in it. These extents are created when a function such as buffer-substring is called on a region with duplicable extents in it. When the string is inserted into a buffer, the extents are inserted along with it. See Duplicable Extents.

See Text, for information about functions that display strings or copy them into buffers. See Character Type, and String Type, for information about the syntax of characters and strings.


Next: , Previous: , Up: Strings and Characters   [Contents][Index]