GNU Info

Info Node: (elisp)String Basics

(elisp)String Basics


Next: Predicates for Strings Up: Strings and Characters
Enter node , (file) or (file)node

String and Character Basics
===========================

   Characters are represented in Emacs Lisp as integers; whether an
integer is a character or not is determined only by how it is used.
Thus, strings really contain integers.

   The length of a string (like any array) is fixed, and cannot be
altered once the string exists.  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.)

   Since strings are arrays, and therefore sequences as well, you can
operate on them with the general array and sequence functions.  (Note:
Sequences Arrays Vectors.)  For example, you can access or change
individual characters in a string using the functions `aref' and `aset'
(Note: Array Functions).

   There are two text representations for non-ASCII characters in Emacs
strings (and in buffers): unibyte and multibyte (Note: Text
Representations).  An ASCII character always occupies one byte in a
string; in fact, when a string is all ASCII, there is no real
difference between the unibyte and multibyte representations.  For most
Lisp programming, you don't need to be concerned with these two
representations.

   Sometimes key sequences are represented as strings.  When a string is
a key sequence, string elements in the range 128 to 255 represent meta
characters (which are large integers) rather than character codes in
the range 128 to 255.

   Strings cannot hold characters that have the hyper, super or alt
modifiers; they can hold ASCII control characters, but no other control
characters.  They do not distinguish case in ASCII control characters.
If you want to store such characters in a sequence, such as a key
sequence, you must use a vector instead of a string.  Note: Character
Type, for more information about the representation of meta and other
modifiers for keyboard input characters.

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

   Like a buffer, a string can contain text properties for the
characters in it, as well as the characters themselves.  Note: Text
Properties.  All the Lisp primitives that copy text from strings to
buffers or other strings also copy the properties of the characters
being copied.

   Note: Text, for information about functions that display strings or
copy them into buffers.  Note: Character Type, and Note: String
Type, for information about the syntax of characters and strings.
Note: Non-ASCII Characters, for functions to convert between text
representations and to encode and decode character codes.


automatically generated by info2www version 1.2.2.9