Chapter 18
Strings

 18.1 String Access
 18.2 String Comparison
 18.3 String Construction and Manipulation

A string is a specialized vector (one-dimensional array) whose elements are characters.

X3J13 voted in March 1989 to eliminate the type string-char and to redefine the type string to be the union of one or more specialized vector types, the types of whose elements are subtypes of the type character.

Any string-specific function defined in this chapter whose name begins with the prefix string will accept a symbol instead of a string as an argument provided that the operation never modifies that argument; the print name of the symbol is used. In this respect the string-specific sequence operations are not simply specializations of generic versions; the generic sequence operations described in chapter 14 never accept symbols as sequences. This slight inelegance is permitted in Common Lisp in the name of pragmatic utility. One may get the effect of having a generic sequence function operate on either symbols or strings by applying the coercion function string to any argument whose data type is in doubt.

Note that this remark, predating the design of the Common Lisp Object System, uses the term “generic” in a generic sense and not necessarily in the technical sense used by CLOS (see chapter 2).

Also, there is a slight non-parallelism in the names of string functions. Where the suffixes equalp and eql would be more appropriate, for historical compatibility the suffixes equal and = are used instead to indicate case-insensitive and case-sensitive character comparison, respectively.

Any Lisp object may be tested for being a string by the predicate stringp.

Note that strings, like all vectors, may have fill pointers (though such strings are not necessarily simple). String operations generally operate only on the active portion of the string (below the fill pointer). See fill-pointer and related functions.