Some programming languages have a feature for creating multi-line literal strings, for example:
some stuff ... <<EOF
this is all part of the string
as is this
\ is a literal slash
\n is a literal \ followed by a literal n
the string ends on the next line
EOF
Question: Does Clojure have something similar to this? I realize that "
handles multi-line fine, but I want it to also properly handle \
as a literal.
Thanks!
You might be interested in this little function.
(defn long-str [& strings] (clojure.string/join "\n" strings))
You'd use like so
(long-str "This is the first line. Implicitly I want a new line"
"When I put a new line in the function call to create a new line")
This does require extra double quotes, but would be closer to what you want.
If you need a \
character in the string, just escape it. You don't have to do anything additional to support multiline strings, for example:
"hello \\
there \\
world "
=> "hello \\\nthere \\\nworld"
EDIT :
Now that you've clarified that you don't want to escape the \
character, I'm afraid that Clojure doesn't offer a special syntax for escaping characters, this has been asked before. In essence, Clojure deals with the same string syntax as Java, with no special syntax available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With