Access to Strings

A character of a string is accessed by specifying the string and the index of the desired character.

(string-ref string i)
accesses the ith character of string. i must be in the range 0 to k - 1, where k is the length of the string.

(string-set! string i char)
sets the ith character of string to be char.


> (define str "Hook 'em!")
str

> (string-ref str 0) #\H

> (string-set! str 3 #\p) "Hoop 'em!"

> (string-length str) 9

Contents    Page-10    Prev    Next    Page+10    Index