18.1 String Access

The following functions access a single character element of a string.

[Function] char string index
[Function] schar simple-string index

The given index must be a non-negative integer less than the length of string, which must be a string. The character at position index of the string is returned as a character object.

As with all sequences in Common Lisp, indexing is zero-origin. For example:

(char "Floob-Boober-Bab-Boober-Bubs" 0)  #\F
(char "Floob-Boober-Bab-Boober-Bubs" 1)  #\l

See aref and elt. In effect,

(char s j)  (aref (the string s) j)

setf may be used with char to destructively replace a character within a string.

For char, the string may be any string; for schar, it must be a simple string. In some implementations of Common Lisp, the function schar may be faster than char when it is applicable.