Evaluates exprs in a context in which *out* is bound to a fresh
StringWriter. Returns the string created by any nested printing
calls.
;; Instead of printing the following will place the output normally ;; sent to standard out to a string. user=> (with-out-str (println "this should return as a string")) "this should return as a string\n"
(defmacro with-out-str
"Evaluates exprs in a context in which *out* is bound to a fresh
StringWriter. Returns the string created by any nested printing
calls."
{:added "1.0"}
[& body]
`(let [s# (new java.io.StringWriter)]
(binding [*out* s#]
~@body
(str s#))))
Comments top
No comments for with-out-str. Log in to add a comment.