從字串建立輸入流
巨集 WITH-INPUT-FROM-STRING
可用於從字串生成流。
(with-input-from-string (str "Foobar")
(loop for i from 0
for char = (read-char str nil nil)
while char
do (format t "~d: ~a~%" i char)))
; 0: F
; 1: o
; 2: o
; 3: b
; 4: a
; 5: r
;=> NIL
同樣可以使用 MAKE-STRING-INPUT-STREAM
手動完成 。
(let ((str (make-string-input-stream "Foobar")))
(loop for i from 0
for char = (read-char str nil nil)
while char
do (format t "~d: ~a~%" i char)))