Go to the previous, next section.
procedure: make-string k [char]
Returns a newly allocated string of length k. If you specify
char, all elements of the string are initialized to char,
otherwise the contents of the string are unspecified. Char must
satisfy the predicate char-ascii?
.
(make-string 10 #\x) => "xxxxxxxxxx"
Returns a newly allocated string consisting of the specified characters.
The arguments must all satisfy char-ascii?
.
(string #\a) => "a" (string #\a #\b #\c) => "abc" (string #\a #\space #\b #\space #\c) => "a b c" (string) => ""
For compatibility with old code, char->string
is a synonym for
this procedure.
procedure: list->string char-list
Char-list must be a list of ASCII characters.
list->string
returns a newly allocated string formed from the
elements of char-list. This is equivalent to (apply string
char-list)
. The inverse of this operation is
string->list
.
(list->string '(#\a #\b)) => "ab" (string->list "Hello") => (#\H #\e #\l #\l #\o)
Returns a newly allocated copy of string.
Note regarding variable-length strings: the maximum length of the result depends only on the length of string, not its maximum length. If you wish to copy a string and preserve its maximum length, do the following:
(define (string-copy-preserving-max-length string) (let ((length)) (dynamic-wind (lambda () (set! length (string-length string)) (set-string-length! string (string-maximum-length string))) (lambda () (string-copy string)) (lambda () (set-string-length! string length)))))
Go to the previous, next section.