string-split

Name

string-split -- Split a string into substrings

Type: function

Synopsis

string-split( string delim, list);

Arguments

string

An instance of <string>.

delim

The delimitation on which to break string. May be a <string>, <char>, or a <function>.

Return Values

list

The list of substrings of string which are delimited by delim.

Description

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.