Next: , Previous: , Up: baselib   [Index]


4.11 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.

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.

NOTE Implementors should make string-ref run in constant 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=? "Strause" "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" "a")      ⇒ #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-for-each proc string1 string2

The strings must all have the same length. proc should accept as many arguments as there are strings.

The string-for-each procedure applies proc element–wise to the characters of the strings for its side effects, in order from the first characters to the last. proc is always called in the same dynamic environment as string-for-each itself. The return values of string-for-each are unspecified.

Analogous to for-each.

Implementation responsibilities: The implementation must check the restrictions on proc to the extent performed by applying it as described. An implementation may check whether proc is an appropriate argument before applying it.

Procedure: string-copy string

Return a newly allocated copy of the given string.


Next: , Previous: , Up: baselib   [Index]