Topic Options
#57228 - 09/24/19 12:04 PM how to separate strings between delimiters
bbauser Offline
OL Newbie

Registered: 09/24/19
Posts: 4
I have the following string
'|a:100 b:200 c:300|a:200 b:200 c:300'

I want to assign them to variables like so
&string1:= 'a:100 b:200 c:300'
&string2:= 'a:200 b:300 c:400'

how would I do that without having to do it manually like I did above?

I was thinking of using search() or pos(), but I noticed pos() only looks for the first instance and I'm not exactly sure how to do it with search(). Could someone please assist?

Top
#57231 - 09/26/19 10:42 AM Re: how to separate strings between delimiters [Re: bbauser]
Philippe F. Offline
OL Expert

Registered: 09/06/00
Posts: 1928
Loc: Objectif Lune, Montreal, Qc
Use something like this:
Code:
define(&line,string,@(1,1,50))


define(&values,arraystring,['','','','','','','',''])
define(&counter,integer,0)
search(&line,'|')
   if(&line<>'')
        &values[&counter]:=&line
        &counter:=&counter+1
   endif()
endsearch()
&values[&counter]:=&line
define(&i,integer,0)
for(&i,0,1,&counter)
        show(&values[&i])
        crlf()
endfor()
_________________________
Technical Product Manager
I don't want to achieve immortality through my work; I want to achieve immortality through not dying - Woody Allen

Top