Strings

Strings are sequences of characters. The length of a string is the number of characters that it contains. This number is fixed when the string is created. The valid indices of a string are the 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.

Kawa note: Kawa’s implementation of strings that contain surrogate characters does not quite follow the R6RS specification. Specifically indexing into such a string retrieves a surrogate rather than a Unicode scalar value. It is not clear what the best solution is - there is a tradeoff between performance, compatibility with R6RS, and interoperability with Java APIs.

Procedure: string? obj

Return #t if obj is a string, #f otherwise.

Procedure: make-string k

Procedure: make-string k char

Return a newly allocated string of length k. If char is given, then all elements of the string are initialized to char, otherwise the contents of the string are unspecified.

Procedure: string char

Return a newly allocated string composed of the arguments.

Procedure: string-length string

Return the number of characters in the given string as an exact integer object.

Procedure: string-ref string k

k must be a valid index of string. The string-ref procedure returns character k of string using zero–origin indexing.

time.

Procedure: string=? string1 string2 string3

Return #t if the strings are the same length and contain the same characters in the same positions. Otherwise, the string=? procedure returns #f.

(string=? "Straße" "Strasse")    ⇒ #f

Procedure: string<? string1 string2 string3

Procedure: string>? string1 string2 string3

Procedure: string<=? string1 string2 string3

Procedure: string>=? string1 string2 string3

These procedures are the lexicographic extensions to strings of the corresponding orderings on characters. For example, string<? is the lexicographic ordering on strings induced by the ordering char<? on characters. If two strings differ in length but are the same up to the length of the shorter string, the shorter string is considered to be lexicographically less than the longer string.

(string<? "z" "ß")      ⇒ #t
(string<? "z" "zz")     ⇒ #t
(string<? "z" "Z")      ⇒ #f

Procedure: substring string start end

string must be a string, and start and end must be exact integer objects satisfying:

0 <= start <= end <= (string-length string)

The substring procedure returns a newly allocated string formed from the characters of string beginning with index start (inclusive) and ending with index end (exclusive).

Procedure: string-append string

Return a newly allocated string whose characters form the concatenation of the given strings.

Procedure: string->list string

Procedure: list->string list

list must be a list of characters.

The string->list procedure returns a newly allocated list of the characters that make up the given string.

The list->string procedure returns a newly allocated string formed from the characters in list.

The string->list and list->string procedures are inverses so far as equal? is concerned.

Procedure: string-copy string

Returns a newly allocated copy of the given string.