Common LISP Hints: Strings

## 14. Strings

A string is a sequence of characters between double quotes. LISP represents a string as a variable-length array of characters. You can write a string which contains a double quote by preceding the quote with a backslash; a double backslash stands for a single backslash. For example:

> `

>     "abcd" has 4 characters
>     "\"" has 1 character
>     "\\" has 1 character

> `

Here are some functions for dealing with strings:

> `

>     > (concatenate 'string "abcd" "efg")
>     "abcdefg"
>     > (char "abc" 1)
>     #\b                     ;LISP writes characters preceded by #\
>     > (aref "abc" 1)
>     #\b                     ;remember, strings are really arrays

> `

The `concatenate` function can actually work with any type of sequence:

> `

>     > (concatenate 'string '(#\a #\b) '(#\c))
>     "abc"
>     > (concatenate 'list "abc" "de")
>     (#\a #\b #\c #\d #\e)
>     > (concatenate 'vector '#(3 3 3) '#(3 3 3))
>     #(3 3 3 3 3 3)

> `