Multisplit: Difference between revisions
Content added Content deleted
(Ruby: added other required example (and made output format match what I see)) |
(→{{header|J}}: icon) |
||
Line 52: | Line 52: | ||
<code>System.StringSplitOptions.None</code> specifies that empty strings should be included in the result. |
<code>System.StringSplitOptions.None</code> specifies that empty strings should be included in the result. |
||
=={{header|Icon}} and {{header|Unicon}}== |
|||
<lang Icon>procedure main() |
|||
s := "a!===b=!=c" |
|||
# just list the tokens |
|||
every writes(multisplit(s,["==", "!=", "="])," ") | write() |
|||
# list tokens |
|||
every ((p := "") ||:= t := multisplit(s,sep := ["==", "!=", "="])) | break write() do |
|||
if t == !sep then writes(t," (",*p+1-*t,") ") else writes(t," ") |
|||
end |
|||
procedure multisplit(s,L) |
|||
s ? while not pos(0) do { |
|||
t := =!L | 1( arb(), match(!L)|pos(0) ) |
|||
suspend t |
|||
} |
|||
end |
|||
procedure arb() |
|||
suspend .&subject[.&pos:&pos <- &pos to *&subject + 1] |
|||
endd</lang> |
|||
=={{header|J}}== |
=={{header|J}}== |