Adds to split() a code example using a set of separators.
This commit is contained in:
parent
a840a4ce53
commit
3ff2f7fbbc
1 changed files with 18 additions and 1 deletions
|
|
@ -186,7 +186,24 @@ iterator split*(s: string, seps: set[char] = Whitespace): string =
|
||||||
## for word in split(";;this;is;an;;example;;;", {';'}):
|
## for word in split(";;this;is;an;;example;;;", {';'}):
|
||||||
## writeln(stdout, word)
|
## writeln(stdout, word)
|
||||||
##
|
##
|
||||||
## produces the same output.
|
## produces the same output. The code:
|
||||||
|
##
|
||||||
|
## .. code-block:: nimrod
|
||||||
|
## let date = "2012-11-20T22:08:08.398990"
|
||||||
|
## let separators = {' ', '-', ':', 'T'}
|
||||||
|
## for number in split(date, separators):
|
||||||
|
## writeln(stdout, number)
|
||||||
|
##
|
||||||
|
## Results in:
|
||||||
|
##
|
||||||
|
## .. code-block:: nimrod
|
||||||
|
## "2012"
|
||||||
|
## "11"
|
||||||
|
## "20"
|
||||||
|
## "22"
|
||||||
|
## "08"
|
||||||
|
## "08.398990"
|
||||||
|
##
|
||||||
var last = 0
|
var last = 0
|
||||||
assert(not ('\0' in seps))
|
assert(not ('\0' in seps))
|
||||||
while last < len(s):
|
while last < len(s):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue