Characters

Characters

Robbert Haarman

2010-12-11


Introduction

Characters are fundamental building blocks, but manipulating them directly is actually quite rare. Still, there are some procedures that do just that, which are discussed in this part.

Characters can be written in two closely related ways: #\character and #\character name. An example of the first case is #\a, an example of the second case is #\newline.


Operations on Characters


; Test if something is a character
(char? #\a) ; => #t
(char? #\space) ; => #t
(char? 1) ; => #f
(char? #\1) ; => #t

; Compare characters
(char=? #\a #\a) ; => #t
(char=? #\a #\b) ; => #f
(char<? #\a #\b) ; => #t
(char>? #\a #\b) ; => #f
(char<=? #\a #\a) ; => #t
(char>=? #\a #\b) ; => #f

(char=? #\a #\A) ; => #f

; Case-insensitive comparison
(char-ci=? #\a #\A) ; > #t

; Also char-ci<?, char-ci>=?, etc.

; Character classes
(char-alphabetic? #\a) ; => #t
(char-alphabetic? #\1) ; => #f
(char-numeric? #\a) ; => #f
(char-numeric? #\1) ; => #t
(char-whitespace? #\a) ; => #f
(char-whitespace? #\space) ; => #t
(char-upper-case? #\a) ; => #f
(char-lower-case? #\a) ; => #t

; Convert case
(char-upcase #\a) ; => #\A
(char-downcase #\A) ; => #\a
(char-downcase #\1) ; => #\1
Valid XHTML 1.1! Valid CSS! Viewable with Any Browser