Multisplit: Difference between revisions

Updated to work with Nim 1.4: added missing parameter type, replaced ".. <" with "..< ".
(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,: string; sep: openArray[string]): tuple[token: string, isSep: bool] =
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 .. < i], false)
yield (s, true)
lastMatch = i + s.len
Line 1,291:
break
inc i
if i > lastMatch: yield (text[lastMatch .. < i], false)
 
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>
Anonymous user