Strings

Strings are sequences of characters. Strings are written as sequences of characters enclosed within quotation marks ("). Within a string literal, various escape sequences represent characters other than themselves. Escape sequences always start with a backslash (\):

\a : alarm, U+0007 {\b : backspace, U+0008 46 Revised7 Scheme %\t : character tabulation, U+0009 \n : linefeed, U+000A i\r : return, U+000D n\" : double quote, U+0022 c\\ : backslash, U+005C l\| : vertical line, U+007C \{intraline whitespace}*{line ending} {intraline whitespace}* : nothing <\x{hex scalar valuer}; : specified character (note the terminating semi-colon).

The result is unspecified if any other character in a string occurs after a backslash.

Except for a line ending, any character outside of an escape sequence stands for itself in the string literal. A line ending which is preceded by \{intraline whitespace} expands to nothing (along with any trailing intraline whitespace), and can be used to indent strings for improved legibility. Any other line ending has the same effect as inserting a \n character into the string.

Examples:

"The word \"recursion\" has many meanings." "Another example:\ntwo lines of text" "Here's text \ containing just one line" "\x03B1; is named GREEK SMALL LETTER ALPHA."

The length of a string is the number of characters that it contains. This number is an exact, non-negative integer that is fixed when the string is created. The valid indexes of a string are the exact non-negative integers less than the length of the string. The first character of a string has index 0, the second has index 1, and so on. difference between upper and lower case characters. The versions that ignore case end with "-ci" (for "case insensitive").

(string? obj ) procedure
Returns #t if obj is a string, otherwise returns #f.

(make-string k ) procedure
(make-string k char ) procedure
The make-string procedure returns a newly allocated string of length k. If char is given, then all the characters of the string are initialized to char, otherwise the contents of the string are unspecified.

(string char ... ) procedure
Returns a newly allocated string composed of the arguments. It is analogous to list.

(string-length string ) procedure
Returns the number of characters in the given string.

(string-ref string k ) procedure
It is an error if k is not a valid index of string.

The string-ref procedure returns character k of string using zero-origin indexing. There is no requirement for this procedure to execute in constant time.

(string-set! string k char ) special form
It is an error if k is not a valid index of string.

The string-set! procedure stores char in element k of string. There is no requirement for this procedure to execute in constant time.
(define (f) (make-string 3 #\*)) (string-set! (f) 0 #\?) ==> unspecified

(string=? string1 string2 string3 ... ) procedure
Returns #t if all the strings are the same length and contain exactly the same characters in the same positions, otherwise returns #f.

(string-ci=? string1 string2 string3 ... ) char library procedure
Returns #t if, after case-folding, all the strings are the same length and contain the same characters in the same positions, otherwise returns #f. Specifically, these procedures behave as if string-foldcase were applied to their arguments before comparing them.

(string<? string1 string2 string3 ... ) procedure
(string-ci<? string1 string2 string3 ... ) char library procedure
(string>? string1 string2 string3 ... ) procedure
(string-ci>? string1 string2 string3 ... ) procedure
(string<=? string1 string2 string3 ... ) procedure
(string-ci<=? string1 string2 string3 ... ) char library procedure
(string>=? string1 string2 string3 ... ) procedure
(string-ci>=? string1 string2 string3 ... ) char library procedure
These procedures return #t if their arguments are (respectively): monotonically increasing, monotonically decreasing, monotonically non-decreasing, or monotonically nonincreasing. These predicates are transitive.
In all cases, a pair of strings must satisfy exactly one of string<?, string=?, and string>?, and must satisfy string<=? if and only if they do not satisfy string>? and string>=? if and only if they do not satisfy string<?.

The "-ci" procedures behave as if they applied string-foldcase to their arguments before invoking the corresponding procedures without "-ci".

(substring string start end ) procedure
The substring procedure returns a newly allocated string formed from the characters of string beginning with index start and ending with index end. This is equivalent to calling string-copy with the same arguments, but is provided for backward compatibility and stylistic flexibility.

(string-append string ... ) procedure
Returns a newly allocated string whose characters are the concatenation of the characters in the given strings.

(string->list string ) procedure
(string->list string start ) procedure
(string->list string start end ) procedure
(list->string list ) procedure
It is an error if any element of list is not a character.

The string->list procedure returns a newly allocated list of the characters of string between start and end. list-> string returns a newly allocated string formed from the elements in the list list . In both procedures, order is preserved. string->list and list->string are inverses so far as equal? is concerned.

(string-copy string ) procedure
(string-copy string start ) procedure
(string-copy string start end ) procedure
Returns a newly allocated copy of the part of the given string between start and end.

(string-copy! to at from ) procedure
(string-copy! to at from start ) procedure
(string-copy! to at from start end ) procedure
It is an error if at is less than zero or greater than the length of to. It is also an error if (- (string-length to) at) is less than (- end start).

Copies the characters of string from between start and end to string to, starting at at. The order in which characters are copied is unspecified, except that if the source and destination overlap, copying takes place as if the source is first copied into a temporary string and then into the destination.
(define a "12345") (define b (string-copy "abcde")) (string-copy! b 1 a 0 2) b ==> "a12de"

(string-fill! string fill ) procedure
(string-fill! string fill start ) procedure
(string-fill! string fill start end ) procedure
It is an error if fill is not a character.

The string-fill! procedure stores fill in the elements of string between start and end.

husk-scheme online documentation rev 3.19.3 (2016.07.10)