escape

added
1.2

ns
clojure.string

type
function

(escape s cmap)

Return a new string, using cmap to escape each character ch
from s as follows:

If (cmap ch) is nil, append ch to the new string.
If (cmap ch) is non-nil, append (str (cmap ch)) instead.

                ;; There should be no space between the \\ and the &, but I don't know how
;; to create that in an example yet.
user=> (clojure.string/escape "I want 1 < 2 as HTML, & other good things."
               {\\< "&lt;", \\> "&gt;", \\& "&amp;"})
"I want 1 &lt; 2 as HTML, &amp; other good things."