Next: , Previous: Comparison of Strings, Up: Strings


6.4 Alphabetic Case in Strings

— procedure: string-capitalized? string
— procedure: substring-capitalized? string start end

These procedures return #t if the first word in the string (substring) is capitalized, and any subsequent words are either lower case or capitalized. Otherwise, they return #f. A word is defined as a non-null contiguous sequence of alphabetic characters, delimited by non-alphabetic characters or the limits of the string (substring). A word is capitalized if its first letter is upper case and all its remaining letters are lower case.

          (map string-capitalized? '(""    "A"    "art"  "Art"  "ART"))
                                 => (#f    #t     #f     #t     #f)
     
— procedure: string-upper-case? string
— procedure: substring-upper-case? string start end
— procedure: string-lower-case? string
— procedure: substring-lower-case? string start end

These procedures return #t if all the letters in the string (substring) are of the correct case, otherwise they return #f. The string (substring) must contain at least one letter or the procedures return #f.

          (map string-upper-case?  '(""    "A"    "art"  "Art"  "ART"))
                                 => (#f    #t     #f     #f     #t)
     
— procedure: string-capitalize string
— procedure: string-capitalize! string
— procedure: substring-capitalize! string start end

string-capitalize returns a newly allocated copy of string in which the first alphabetic character is uppercase and the remaining alphabetic characters are lowercase. For example, "abcDEF" becomes "Abcdef". string-capitalize! is the destructive version of string-capitalize: it alters string and returns an unspecified value. substring-capitalize! destructively capitalizes the specified part of string.

— procedure: string-downcase string
— procedure: string-downcase! string
— procedure: substring-downcase! string start end

string-downcase returns a newly allocated copy of string in which all uppercase letters are changed to lowercase. string-downcase! is the destructive version of string-downcase: it alters string and returns an unspecified value. substring-downcase! destructively changes the case of the specified part of string.

          (define str "ABCDEFG")          =>  unspecified
          (substring-downcase! str 3 5)   =>  unspecified
          str                             =>  "ABCdeFG"
     
— procedure: string-upcase string
— procedure: string-upcase! string
— procedure: substring-upcase! string start end

string-upcase returns a newly allocated copy of string in which all lowercase letters are changed to uppercase. string-upcase! is the destructive version of string-upcase: it alters string and returns an unspecified value. substring-upcase! destructively changes the case of the specified part of string.