"" string

syntaxsince v0.0-1853 in clojure in ednEdit

A string of characters.

  • "..."
  • "single line string"
"multi
line
string"

Details:

ClojureScript strings compile to JavaScript strings.

Standard escape characters such as \" are supported, as well as unicode escape characters:

unicode characters constraints
\uXXXX XXXX must have 4 digits outside 0xD7FF-0xE000
\oXXX XXX is octal between 0 and 0377

Examples:

"foo"
;;=> "foo"

"hello
     world"
;;=> "hello\n     world"

Characters can be escaped:

(println "foo\nbar")
;; prints:
;;   foo
;;   bar

See Also:


Reader code @ tools.reader:src/main/clojure/clojure/tools/reader.clj
(defn- read-string*
  [reader _ opts pending-forms]
  (loop [sb (StringBuilder.)
         ch (read-char reader)]
    (case ch
      nil (err/throw-eof-reading reader :string sb)
      \\ (recur (doto sb (.append (escape-char sb reader)))
                (read-char reader))
      \" (str sb)
      (recur (doto sb (.append ch)) (read-char reader)))))

Reader table @ tools.reader:src/main/clojure/clojure/tools/reader.clj
(defn- macros [ch]
  (case ch
    \" read-string*
    \: read-keyword
    \; read-comment
    \' (wrapping-reader 'quote)
    \@ (wrapping-reader 'clojure.core/deref)
    \^ read-meta
    \` read-syntax-quote ;;(wrapping-reader 'syntax-quote)
    \~ read-unquote
    \( read-list
    \) read-unmatched-delimiter
    \[ read-vector
    \] read-unmatched-delimiter
    \{ read-map
    \} read-unmatched-delimiter
    \\ read-char*
    \% read-arg
    \# read-dispatch
    nil))