Sure, if what you really want is n
variables named w1
, w2
, ... wn
:
do i = 1 by 1 while myline <> ''
parse var myline word (delim) myline
interpret "w" || i "= word"
end
But the Rexx-y way to do this is using a "stem array":
delim = ';'
do i = 1 by 1 while myline <> ''
parse var myline w.i (delim) myline
end
w.0 = i-1
or even:
do i = 1 by 1 while myline <> ''
parse var myline w.i ';' myline
end
w.0 = i-1
When you're done, you have an array w.
with it's count in w.0
and the n
words in w.1
, w.2
, ... up through w.n
. This is better because Rexx has special handling for the part following the .
: you can use any variable, and its value will be used instead. So printing all those words is just:
do i = 1 to w.0
say w.i
end
Or re-assembling them is just:
line = ""
do i = 1 to w.0
line = line || w.i || ';'
end