philipbohun.com

Glojure by Example: Strings and Characters

Strings are sequences of characters. count and subs count characters, not bytes, so a character such as é is one unit. Character literals look like \a. first returns the first character.

(require '[clojure.string :as string])

(def greeting "héllo")
(println (count greeting))
(println (subs greeting 1 4))
(println (first greeting))
(println (string/upper-case greeting))
(println (string/reverse greeting))

subs takes a start index and an exclusive end index.

$ glj strings-and-characters.glj
5
éll
h
HÉLLO
olléh

Next example: Namespaces.