[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.10.7 String utilities

Function: substring string start end
[R5RS]

Function: string-append string ...
[R5RS]

Function: string->list string &optional start end
Function: list->string list
[R5RS+][SRFI-13]

Function: string-copy string &optional start end
[R5RS+][SRFI-13]

Function: string-fill! string char &optional start end
[R5RS+][SRFI-13] Fills string by char. Optional start and end limits the effective area.
 
(string-fill! "orange" #\X)
  => "XXXXXX"
(string-fill! "orange" #\X 2 4)
  => "orXXge"

Function: string-join strs &optional delim grammer
[SRFI-13] Concatenate strings in the list strs, with a string delim as `glue'.

The argument grammer may be one of the following symbol to specify how the strings are concatenated.

infix
Use delim between each string. This mode is default. Note that this mode introduce ambiguity when strs is an empty string or a list with a null string.
 
(string-join '("apple" "mango" "banana") ", ") 
  => "apple, mango, banana"
(string-join '() ":")
  => ""
(string-join '("") ":")
  => ""
strict-infix
Works like infix, but empty list is not allowed to strs, thus avoiding ambiguity.
prefix
Use delim before each string.
 
(string-join '("usr" "local" "bin") "/" 'prefix)
  => "/usr/local/bin"
(string-join '() "/" 'prefix)
  => ""
(string-join '("") "/" 'prefix)
  => "/"
suffix
Use delim after each string.
 
(string-join '("a" "b" "c") "&" 'suffix)
  => "a&b&c&"
(string-join '() "&" 'suffix)
  => ""
(string-join '("") "&" 'suffix)
  => "&"

Function: string-scan string item &optional return
Scan item (either a string or a character) in string. The return argument specifies what value should be returned when item is found in string. It must be one of the following symbols.

index
Returns the index in string if item is found, or #f. This is the default behavior.
 
(string-scan "abracadabra" "ada") => 5
(string-scan "abracadabra" #\c) => 4
(string-scan "abracadabra" "aba") => #f
before
Returns a substring of string before item, or #f if item is not found.
 
(string-scan "abracadabra" "ada" 'before) => "abrac"
(string-scan "abracadabra" #\c 'before) => "abra"
after
Returns a substring of string after item, or #f if item is not found.
 
(string-scan "abracadabra" "ada" 'after) => "bra"
(string-scan "abracadabra" #\c 'after) => "adabra"
before*
Returns a substring of string before item, and the substring after it. If item is not found, returns (values #f #f).
 
(string-scan "abracadabra" "ada" 'before*)
  => "abrac" and "adabra"
(string-scan "abracadabra" #\c 'before*)
  => "abra" and "cadabra"
after*
Returns a substring of string up to the end of item, and the rest. If item is not found, returns (values #f #f).
 
(string-scan "abracadabra" "ada" 'after*)
  => "abracada" and "bra"
(string-scan "abracadabra" #\c 'after*)
  => "abrac" and "adabra"
both
Returns a substring of string before item and after item. If item is not found, returns (values #f #f).
 
(string-scan "abracadabra" "ada" 'both)
  => "abrac" and "bra"
(string-scan "abracadabra" #\c 'both)
  => "abra" and "adabra"

Function: string-split s char


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Ken Dickey on November, 28 2002 using texi2html