Is it possible to supply multiple subarrays to be cut from a larger array?
This works, but it's not very efficient on huge strings... still faster
than boxing with cut. I assume it's because it's copying the string for
every slice
str=: 'ab|111*cd|222'
] (str ];.0~ ,.)"1 (0,2),(3,3),(7,2),:(10,3)
ab
111
cd
222
Background, I'm play with the idea of segmented strings and interested in
passing the indices and length of substrings to be extracted
This works reasonably well:
NB. change 5 to a large number to see difference in speed
str=:; 5 $ ,: ('abc', TAB, '12345',LF)
cutIt=: 3 : 0
tx1=: TAB cut each LF cut y
)
segmentIt=: 3 : 0
start=:0,>: I. (TAB&= +. LF&= ) y
end=:(}. start, # str)-start
slices=:(}: (start,.<:end))
parts=:(str ];.0~ ,.)"1 slices
)
smoutput ''
smoutput 'cutIt ',":(timespacex 'cutIt str')
smoutput 'segmentIt ',": (timespacex 'segmentIt str')
smoutput 'size of string: ', ":((1e6) %~ 7!:5 <'str')
smoutput 'size of boxed: ', ":((1e6) %~ 7!:5 <'tx1')
smoutput 'size of parts: ',": ((1e6) %~ 7!:5 <'parts')
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm