Previous: , Up: srfi string-ports   [Index]


2.4.4 Specification

This specification is taken from the MacScheme Reference Manual.

Function: open-input-string string

Take a string and return an input port that delivers characters from the string. The port can be closed by close-input-port, though its storage will be reclaimed by the garbage collector if it becomes inaccessible.

Example:

(define p (open-input-string "(a . (b . c . ())) 34"))

(input-port? p)                 =>  #t
(read p)                        =>  (a b c)
(read p)                        =>  34
(eof-object? (peek-char p))     =>  #t
Function: open-output-string

Return an output port that will accumulate characters for retrieval by get-output-string. The port can be closed by the procedure close-output-port, though its storage will be reclaimed by the garbage collector if it becomes inaccessible.

(let ([q (open-output-string)]
      [x '(a b c)])
  (write (car x) q)
  (write (cdr x) q)
  (get-output-string q))
  =>  "a(b c)"
Function: get-output-string output-port

Given an output port created by open-output-string, return a string consisting of the characters that have been output to the port so far.