Posts: 153
Threads: 33
Joined: Aug 2009
07-15-2019, 10:18 PM
(This post was last modified: 07-16-2019, 01:49 AM by MAGNET.)
Hello!
How to get the following output?
str s="2 text[]4-6 text2[]8 text3"
Output:
2 text
4 text2
5 text2
6 text2
8 text3
Already tried foreach +__MapIntStr but cant get it to work if s contains a group, in this case 4-6
Thank you!
Posts: 1,337
Threads: 61
Joined: Jul 2006
07-18-2019, 05:51 PM
(This post was last modified: 07-18-2019, 05:52 PM by Kevin.)
one way
str ss s="2 text[]4-6 text2[]8 text3"
foreach ss s
,int iii=findc(ss '-')
,if iii <>-1
,,ss=sub.getNumRange(ss)
,out ss
#sub getNumRange
function~ ~sss
int i ii
ARRAY(CHARRANGE) a
findrx(sss "(\d+)\-(\d+)\s(.+)" 0 4 a)
,for i 0 a.len
,,int offset1(a[1 i].cpMin) length1(a[1 i].cpMax-a[1 i].cpMin)
,,str sn.get(sss offset1 length1)
,,int offset2(a[2 i].cpMin) length2(a[2 i].cpMax-a[2 i].cpMin)
,,str en.get(sss offset2 length2)
,,int offset3(a[3 i].cpMin) length3(a[3 i].cpMax-a[3 i].cpMin)
,,str Etext.get(sss offset3 length3)
,for ii val(sn) val(en)+1
,,str results.formata("%i %s[]" ii Etext)
ret results.trim
Posts: 153
Threads: 33
Joined: Aug 2009
works perfect... thanks a lot for your time!
Regards