A string port reads or writes from a byte string. An input string port can be created from either a byte string or a string; in the latter case, the string is effectively converted to a byte string using string->bytes/utf-8 . An output string port collects output into a byte string, but get-output-string conveniently converts the accumulated bytes to a string.
Input and output string ports do not need to be explicitly closed. The file-position procedure works for string ports in position-setting mode.
+Byte Strings also provides information on bytestrings.
procedure
(string-port? p)→boolean?
p:port?
Added in version 6.0.1.6 of package base.
procedure
(open-input-bytes bstr[name])→(and/c input-port? string-port? )
bstr:bytes?
'apples
'(42 day)
#"the cow jumped over the moon\nthe little dog\n"))"the cow jumped over the moon"
+Strings also provides information on strings.
procedure
(open-input-string str[name])→(and/c input-port? string-port? )
str:string?
'(λ (x) x)
"Günter Harder"
"Frédéric Paulin"
procedure
(open-output-bytes [name])→(and/c output-port? string-port? )
#"((1 2 3) (\"Tom\" \"Dick\") ((quote a) (quote b) (quote c)))"
#"\"Hi \"\"there\""
3
5
#"Hi there"
procedure
(open-output-string [name])→(and/c output-port? string-port? )
"((1 2 3) (\"Tom\" \"Dick\") ((quote a) (quote b) (quote c)))"
"\"Hi \"\"there\""
3
5
"Hi there"
procedure
[ reset?start-pos
If reset? is true, then all bytes are removed from the port, and the port’s position is reset to 0; if reset? is #f, then all bytes remain in the port for further accumulation (so they are returned for later calls to get-output-bytes or get-output-string ), and the port’s position is unchanged.
The start-pos and end-pos arguments specify the range of bytes in the port to return; supplying start-pos and end-pos is the same as using subbytes on the result of get-output-bytes , but supplying them to get-output-bytes can avoid an allocation. The end-pos argument can be #f, which corresponds to not passing a second argument to subbytes .
#"((1 2 3) (\"Tom\" \"Dick\") ((quote a) (quote b) (quote c)))"
#" 2 3) (\"Tom\" "
#"((1 2 3) (\"Tom\" \"Dick\") ((quote a) (quote b) (quote c)))"
#""
procedure
(get-output-string out)→string?
"hello"