The macro WITH-OUTPUT-TO-STRING
can be used to create a string output stream, and return the resulting string at the end.
(with-output-to-string (str)
(write-line "Foobar!" str)
(write-string "Barfoo!" str))
;=> "Foobar!
; Barfoo!"
The same can be done manually using MAKE-STRING-OUTPUT-STREAM
and GET-OUTPUT-STREAM-STRING
.
(let ((str (make-string-output-stream)))
(write-line "Foobar!" str)
(write-string "Barfoo!" str)
(get-output-stream-string str))