Returns data from a comma delimited string such as:
2,1,"Buy medicine before","you go",2,4,40,1,0,5,68,0,0,0,1,0
Just specify which chunk(pos) you want. For instance,
getChunk$(4,text$) would return "you go", including the quotes. Commas inside quotes are ignored, so you get the entire string you expect. Useful for reading in human-readable file formats like game save data.
function getChunk$(pos, text$)
L = len(text$)
quotes = 0
chunk = 0
s = 1
t$ = ""
for i = 1 to L
c$ = mid(text$,i,1)
if c$ = chr(34) then quotes = 1-quotes
if c$ = ","
if quotes = 0 then inc chunk
if chunk = pos
t$ = mid(text$, s, i-s)
exitfunction t$
else
if quotes = 0 then s = i+1
endif
endif
next i
rem end of file is a delimiter as well
inc chunk
if chunk = pos
t$ = mid(text$, s, i-s)
exitfunction t$
endif
endfunction ""