Skip to main content

name-char

name-char Function

Syntax:

name-char name → char-p

Arguments and Values:

name—a string designator .

char-p—a character or nil.

Description:

Returns the character object whose name is name (as determined by string-equali.e., lookup is not case sensitive). If such a character does not exist, nil is returned.

Examples:

(name-char ’space) → #\Space 
(name-char "space") → #\Space
(name-char "Space") → #\Space
(let ((x (char-name #\a)))
(or (not x) (eql (name-char x) #\a))) → true

Exceptional Situations:

Should signal an error of type type-error if name is not a string designator .

See Also:

char-name

Expanded Reference: name-char

Looking up characters by name

name-char returns the character object whose name matches the given string. The lookup is case-insensitive.

(name-char "Space")
=> #\Space
(name-char "Newline")
=> #\Newline
(name-char "SPACE")
=> #\Space
(name-char "space")
=> #\Space

Using a symbol as the name

Since name-char accepts a string designator, you can also pass a symbol.

(name-char 'space)
=> #\Space
(name-char 'newline)
=> #\Newline

Unknown names return NIL

If no character has the given name, name-char returns NIL.

(name-char "NoSuchCharacter")
=> NIL
(name-char "Foo")
=> NIL

Semi-standard character names

The semi-standard characters Tab, Page, Rubout, Linefeed, Return, and Backspace can be looked up by name if supported by the implementation.

(name-char "Tab")
=> #\Tab
(name-char "Return")
=> #\Return
(name-char "Backspace")
=> #\Backspace

Round-tripping with char-name

For any character that has a name, name-char and char-name are inverses.

(char-name (name-char "Space"))
=> "Space"
(char-name (name-char "Newline"))
=> "Newline"

;; For any character with a name:
(let ((name (char-name #\Space)))
(char= (name-char name) #\Space))
=> T