This function breaks the string
up into substrings
delimited by delim
, which may be a string, a character,
or a procedure.
In the latter case, where delim
is a procedure, delim
is presumed to have the interface of a regular expression
search procedure. That is, it must be a procedure of two
arguments (a string and an offset), and return two values
if the pattern is found (the start and ending indexes) and
no values or #f if the pattern is not found.
(string-split "foo bar baz" #\space) ("foo" "bar" "baz")
(string-split ".foo..bar...baz" #\.) ("" "foo" "" "bar" "" "" "baz")
(define p (reg-expr->proc '(+ #\,)))
(string-split "foo,,bar,,,baz" p) ("foo" "bar" "baz")
If the delimitation is by function, and the function matches the empty string at some point in the process of trying to delimit the input string, then an error is signalled.