Multisplit: Difference between revisions
m
→{{header|J}}: clearer result format
(J: simpler) |
m (→{{header|J}}: clearer result format) |
||
Line 819:
=={{header|J}}==
<lang j>multisplit=: {{
'begin sep'=. |:bs=. _,~/:~;(,.&.>i.@#) y I.@E.L:0 x NB.
r=. i.3 0
j=. k=. 0
while.j<#x do.
while. j>k{begin do. k=.k+1 end.
'b s'=. k{bs
if. _=b do. r,.(j}.x);'';'' return. end.
txt=. (j + i. b-j){x
j=. b+s{len
r=.r,.txt;(s
end.
}}</lang>
Line 839 ⟶ 840:
Then, loop through the possibilities, skipping over those separators which would overlap with previously used separators.
The result consists of
Example use:
<lang j> S
┌──┬──┬─┬──┬─┐
├──┼──┼─┼──┼─┤
▲│a │ │b │ │c│
│!=│==│=│!=│ │
├──┼──┼─┼──┼─┤
│1 │3 │6│7 │ │
└──┴──┴─┴──┴─┘
S multisplit '=';'!=';'=='
┌──┬─┬─┬─┬──┬─┐
│a
├──┼─┼─┼─┼──┼─┤
│!=│=│=│=│!=│ │
├──┼─┼─┼─┼──┼─┤
│1 │3│4│6│7 │ │
└──┴─┴─┴─┴──┴─┘
'X123Y' multisplit '1';'12';'123';'23';'3'
┌─┬──┬─┐
├─┼──┼─┤
├─┼──┼─┤
│1│2 │ │
└─┴──┴─┘</lang>
=={{header|Java}}==
|