Node: Strings, Next: , Previous: Characters, Up: Standard Procedures



Strings

STKLOS string constants allow the insertion of arbitrary characters by encoding them as escape sequences. An escape sequence is introduced by a backslash "\". The valid escape sequences are shown in the following table.

Sequence Character inserted
\b Backspace
\e Escape
\n Newline
\t Horizontal Tab
\n Carriage Return
\0abc ASCII character with octal value abc
\xab ASCII character with hexadecimal value ab
\<newline> None (permits to enter a string on several lines)
\<other> <other>

For instance, the string

     "ab\040c\nd\
     e"
     

is the string consisting of the characters #\a, #\b, #\space, #\c, #\newline, #\d and #\e.

string? obj R5RS
Returns #t if obj is a string, otherwise returns #f.

make-string k R5RS
make-string k char R5RS
Make-string returns 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.

string char ... R5RS
Returns a newly allocated string composed of the arguments.

string-length string R5RS
Returns the number of characters in the given string.

string-ref string k R5RS
String-ref returns character k of string using zero-origin indexing (k must be a valid index of string).

string-set! string k char R5RS
String-set! stores char in element k of string and returns void (k must be a valid index of string).
             (define (f) (make-string 3 #\*))
             (define (g) "***")
             (string-set! (f) 0 #\?)  =>  void
             (string-set! (g) 0 #\?)  =>  error
             (string-set! (symbol->string 'immutable)
                          0
                          #\?)  =>  error
          

string=? string1 string2 R5RS
string-ci=? string1 string2 R5RS
Returns #t if the two strings are the same length and contain the same characters in the same positions, otherwise returns #f. String-ci=? treats upper and lower case letters as though they were the same character, but string=? treats upper and lower case as distinct characters.

string<? string1 string2 R5RS
string>? string1 string2 R5RS
string<=? string1 string2 R5RS
string>=? string1 string2 R5RS
string-ci<? string1 string2 R5RS
string-ci>? string1 string2 R5RS
string-ci<=? string1 string2 R5RS
string-ci>=? string1 string2 R5RS
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.

substring string start end R5RS
String must be a string, and start and end must be exact integers satisfying
               0 <= start <= end <= (string-length string).
          
Substring returns a newly allocated string formed from the characters of string beginning with index start (inclusive) and ending with index end (exclusive).

string-append string ... R5RS
Returns a newly allocated string whose characters form the concatenation of the given strings.

string->list string R5RS
list->string list R5RS
String->list returns a newly allocated list of the characters that make up the given string. List->string returns a newly allocated string formed from the characters in the list list, which must be a list of characters. String->list and list->string are inverses so far as equal? is concerned.

string-copy string R5RS
Returns a newly allocated copy of the given string.

string-split str STKLOS Procedure
string-split str delimiters STKLOS Procedure
parses string and returns a list of tokens ended by a character of the delimiters string. If delimiters is omitted, it defaults to a string containing a space, a tabulation and a newline characters.
          (string-split "/usr/local/bin" "/") => ("usr" "local" "bin")
          (string-split "once   upon a time") => ("once" "upon" "a" "time")
          

string-index str1 str2 STKLOS Procedure
Returns the (first) index where str1 is a substring of str2 if it exists; otherwise returns #f.
          (string-index "ca" "abracadabra") =>  4
          (string-index "ba" "abracadabra") =>  #f
          

string-find? str1 str2 STKLOS Procedure
Returns #t if str1 appears somewhere in str2; otherwise returns #f.

string-fill! string char STKLOS Procedure
Stores char in every element of the given string and returns void.

The following string primitives are compatible with SRFI-13 (documentation comes from the SRFI-13 document).

string-downcase str STKLOS Procedure
string-downcase str start STKLOS Procedure
string-downcase str start end STKLOS Procedure
Returns a string in which the upper case letters of string str between the start and end indices have been replaced by their lower case equivalent. If start is omited, it defaults to 0. If end is omited, it defaults to the length of str.
          (string-downcase "Foo BAR")        => "foo bar"
          (string-downcase "Foo BAR" 4)      => "bar"
          (string-downcase "Foo BAR" 4 6)    => "ba"
          

string-downcase! str STKLOS Procedure
string-downcase! str start STKLOS Procedure
string-downcase! str start end STKLOS Procedure
This is the in-place side-effecting variant of string-downcase.
          (string-downcase! (string-copy "Foo BAR") 4)    => "Foo bar"
          (string-downcase! (string-copy "Foo BAR") 4 6)  => "Foo baR"
          

string-upcase str STKLOS Procedure
string-upcase str start STKLOS Procedure
string-upcase str start end STKLOS Procedure
Returns a string in which the lower case letters of string str between the start and end indices have been replaced by their upper case equivalent. If start is omited, it defaults to 0. If end is omited, it defaults to the length of str.

string-upcase! str STKLOS Procedure
string-upcase! str start STKLOS Procedure
string-upcase! str start end STKLOS Procedure
This is the in-place side-effecting variant of string-upcase.

string-titlecase str STKLOS Procedure
string-titlecase str start STKLOS Procedure
string-titlecase str start end STKLOS Procedure
This function returns a string. For every character c in the selected range of str, if c is preceded by a cased character, it is downcased; otherwise it is titlecased. If start is omited, it defaults to 0. If end is omited, it defaults to the length of str. Note that if a start index is specified, then the character preceding s[start] has no effect on the titlecase decision for character s[start].
          (string-titlecase "--capitalize tHIS sentence.")
                   =>  "--Capitalize This Sentence."
          (string-titlecase "see Spot run. see Nix run.")
                   =>  "See Spot Run. See Nix Run."
          (string-titlecase "3com makes routers.")
                   =>  "3Com Makes Routers."
          (string-titlecase "greasy fried chicken" 2)
                   => "Easy Fried Chicken"
          

string-titlecase! str STKLOS Procedure
string-titlecase! str start STKLOS Procedure
string-titlecase! str start end STKLOS Procedure
This is the in-place side-effecting variant of string-titlecase.

string-mutable? obj STKLOS Procedure
Returns #t if obj is a mutable string, otherwise returns #f.
          (string-mutable? "abc")                => #f
          (string-mutable? (string-copy "abc"))  => #t
          (string-mutable? (string #\a #\b #\c)) => #t
          (string-mutable? 12)                   => #f