Skip to main content

stringp

stringp Function

Syntax:

stringp object → generalized-boolean

Arguments and Values:

object—an object.

generalized-boolean—a generalized boolean.

Description:

Returns true if object is of type string; otherwise, returns false.

Examples:

(stringp "aaaaaa") → true 
(stringp #\a) → false

See Also:

typep, string (type)

Notes:

(stringp object) (typep object ’string)

Expanded Reference: stringp

Testing string objects

stringp returns true if its argument is a string, and false otherwise.

(stringp "hello")
=> T

(stringp "")
=> T

(stringp (make-string 5 :initial-element #\x))
=> T

Non-string objects return NIL

Characters, symbols, numbers, and lists are not strings.

(stringp #\a)
=> NIL

(stringp 'hello)
=> NIL

(stringp 42)
=> NIL

(stringp '(#\h #\i))
=> NIL

Vectors of characters that are strings

Arrays with character element types are strings. A general vector containing characters is not.

(stringp (make-array 3 :element-type 'character :initial-element #\a))
=> T

(stringp #(#\h #\e #\l #\l #\o))
=> NIL

Strings with fill pointers are still strings

Even non-simple strings (with fill pointers or adjustable) satisfy stringp.

(stringp (make-array 10 :element-type 'character
:fill-pointer 5
:initial-element #\z))
=> T

Equivalence with typep

(stringp x) is equivalent to (typep x 'string).

(let ((s "test"))
(eql (stringp s) (typep s 'string)))
=> T