Anonymous user
Multisplit: Difference between revisions
Updated to work with Nim 1.4: added missing parameter type, replaced ".. <" with "..< ".
Alextretyak (talk | contribs) m (→{{header|11l}}) |
(Updated to work with Nim 1.4: added missing parameter type, replaced ".. <" with "..< ".) |
||
Line 1,279:
=={{header|Nim}}==
<lang nim>import strutils
iterator tokenize(text
var i, lastMatch = 0
while i < text.len:
for j, s in sep:
if text[i..text.high].startsWith s:
if i > lastMatch: yield (text[lastMatch ..
yield (s, true)
lastMatch = i + s.len
Line 1,291:
break
inc i
if i > lastMatch: yield (text[lastMatch ..
for token, isSep in "a!===b=!=c".tokenize(["==", "!=", "="]):
if isSep: stdout.write '{',token,'}'
else: stdout.write token
echo ""</lang>
{{out}}
<pre>a{!=}{==}b{=}{!=}c</pre>
|