Next: File-Stream Ports Up: Ports Previous: Pipes

## String Ports

Scheme input and output can be read from or collected into a string:

- `(open-input-string string)` creates an input port that reads characters from string.
- `(open-output-string)` creates an output port that accumulates the output into a string.
- `(get-output-string string-output-port)` returns the string accumulated in string-output-port.

String input and output ports do not need to be explicitly closed. The `file-position` procedure, described in section 11.1.5, works specially for string ports.

Example: ``

      (define i (open-input-string "hello world"))
      (define o (open-output-string))
      (write (read i) o)
      (get-output-string o) ; => "hello"