From 3ff2f7fbbc48b1de3f8e7031dfb271862a8878fa Mon Sep 17 00:00:00 2001 From: Grzegorz Adam Hankiewicz Date: Tue, 11 Dec 2012 21:39:05 +0100 Subject: [PATCH] Adds to split() a code example using a set of separators. --- lib/pure/strutils.nim | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 0f11b4d896..8a5061037a 100755 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -186,7 +186,24 @@ iterator split*(s: string, seps: set[char] = Whitespace): string = ## for word in split(";;this;is;an;;example;;;", {';'}): ## 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 assert(not ('\0' in seps)) while last < len(s):