Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

How to get the following output?

str s="2 text[]4-6 text2[]8 text3"

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!
one way

Copy      Help
str ss s="2 text[]4-6 text2[]8 text3"
foreach ss s
,int iii=findc(ss '-')
,if iii <>-1
,out ss        

#sub getNumRange        
function~ ~sss
int i ii
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
works perfect...  thanks a lot for your time! 


Forum Jump:

Users browsing this thread: 1 Guest(s)