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.
open
| string | An instance of <string>. The string to split. |
| character | An 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. |
| val | An instance of <sequence>. |
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.
| pattern | An instance of <string>. The regexp to split on. |
| input | An 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. |
| whole-bunch-of-strings | Instances of <string>. |