split

There are two unrelated functions named split.

Summary
There are two unrelated functions named split.
Splits a string around a given separator character.
Breaks up a string along boundary characters matching a regular expression.

Generic Functions

split

Splits a string around a given separator character.

split("The summer chair / rocking by itself / in the blizzard", '/')
⇒ #("The summer chair ",
" rocking by itself ",
" in the blizzard")

trim?: specifies whether spaces surrounding character should be removed.

split("The summer chair / rocking by itself / in the blizzard",
'/', trim?: #t)
⇒ #("The summer chair",
"rocking by itself",
"in the blizzard")

Consecutive separator characters result in empty strings.

split("Who are you?  Who am I?!", ' ')
⇒ #("Who", "are", "you?", "", "Who", "am", "I?!")

Note: The only defined method is on <byte-string>, and it defaults trim:? to #t.

Exported from

Modifiers

open

Arguments

stringAn instance of <string>.  The string to split.
characterAn instance of <character>.  The character to split around.
start:An instance of <integer>.  Required.
end:An instance of <integer>.  Required.
trim?:An instance of <boolean>.  The default is #f.

Values

valAn instance of <sequence>.

Functions

split

Breaks up a string along boundary characters matching a regular expression.  This is like Perl’s split function.  It searches input for occurrences of pattern, and returns substrings that were delimited by that regexp.  For instance,

split("-", "long-dylan-identifier")

returns values(“long”, “dylan”, “identifier”).  Note that what matched the regexp is left out.  Remove-empty-items, which defaults to true, magically skips over empty items, so that

split("-", "long--with--multiple-dashes")

returns values(“long”, “with”, “multiple”, “dashes”).  Count is the maximum number of strings to return.  If there are n strings and count is specified, the first count - 1 strings are returned as usual, and the count th string is the remainder, unsplit.  So

split("-", "really-long-dylan-identifier", count: 3)

returns values(“really”, “long”, “dylan-identifier”).  If remove-empty-items is #t, empty items aren’t counted.

Start: and end: indicate what part of input should be looked at for delimiters.  They default to the entire string.  For instance,

split("-", "really-long-dylan-identifier", start: 8)

returns values(“really-long”, “dylan”, “identifier”).

The values returned can be stored in a collection as follows.

let (#rest parts) = split(...)

Note: Unlike Perl, empty regular expressions are never legal regular expressions, so there is no way to split a string into a bunch of single character strings.  Of course, in Dylan this is not a useful thing to do (as one can get each character of the string by iteration or by indexing), so this is not really a problem.

Exported from

Arguments

patternAn instance of <string>.  The regexp to split on.
inputAn instance of <string>.  The string to parse and replace pieces of.
count:An instance of <integer> or #f.  If supplied, maximum number of strings to return.  The default is #f.
remove-empty-items:An instance of <object>.  Magically skips empty items when true.  The default is #t.
start:An instance of <integer>.  Where to start parsing the string.  The default is 0.
end:An instance of <integer> or #f.  If defined, where to stop parsing the string.  The default is #f.

Values

whole-bunch-of-stringsInstances of <string>.
There are two unrelated functions named split.
The class of vectors with elements that are eight-bit characters.
The common-dylan module.
Miscellaneous extensions to the Dylan language.
The class of sequences with elements that are characters.
The class of characters.
The class of integers.
The class of boolean values.
The class of collections whose keys are consecutive integers starting from zero.
Parsing a regexp is not cheap, so we cache the parsed regexps and only parse a string if we haven’t seen it before.
The class of all Dylan objects.