Next: , Previous: Construction of Strings, Up: Strings


6.2 Selecting String Components

— procedure: string? object

Returns #t if object is a string; otherwise returns #f.

          (string? "Hi")                  =>  #t
          (string? 'Hi)                   =>  #f
     
— procedure: string-length string

Returns the length of string as an exact non-negative integer.

          (string-length "")              =>  0
          (string-length "The length")    =>  10
     
— procedure: string-null? string

Returns #t if string has zero length; otherwise returns #f.

          (string-null? "")               =>  #t
          (string-null? "Hi")             =>  #f
     
— procedure: string-ref string k

Returns character k of string. K must be a valid index of string.

          (string-ref "Hello" 1)          =>  #\e
          (string-ref "Hello" 5)          error--> 5 not in correct range
     
— procedure: string-set! string k char

Stores char in element k of string and returns an unspecified value. K must be a valid index of string, and char must satisfy the predicate char-ascii?.

          (define str "Dog")              =>  unspecified
          (string-set! str 0 #\L)         =>  unspecified
          str                             =>  "Log"
          (string-set! str 3 #\t)         error--> 3 not in correct range