Hi,
I am trying to parse comma separated numbers in a string (as to send them one by one to another process). Something odd is happening so that my instrument works correctly the first time it starts, but then when it is started again the first item of the string is not converted to a number.
It might look like some k-rate string opcodes somehow retain their state from previous initializations (??)
The csd below shows the problem. Running instr 1 should print the numbers in the string one by one. This happens correctly the first time the instrument runs, but it only prints 2 and 3 the second time the instrument runs.
As a test I have recreated the same procedure with i-time string opcodes in instr 2. This works every time. Sadly, I do need to make it work at k-rate…
All best
Øyvind
instr 1
Snumbers = “1,2,3”
Snumbers strcat Snumbers, “,”
kcomma strindexk Snumbers, “,”
while kcomma > -1 do
Sval strsubk Snumbers, 0, kcomma
kval strtodk Sval
printk2 kval, 10
Snumbers strsubk Snumbers, kcomma+1, -1
kcomma strindexk Snumbers, “,”
od
endin
instr 2
Snumbers = “1,2,3”
Snumbers strcat Snumbers, “,”
icomma strindex Snumbers, “,”
while icomma > -1 do
Sval strsub Snumbers, 0, icomma
ival strtod Sval
print ival
Snumbers strsub Snumbers, icomma+1, -1
icomma strindex Snumbers, “,”
od
endin
;i2 2 .1
;i2 3 .1
Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here