Hi Guy's, made a very handy fast simple to use parser function which works great with basic scripts and some string stuff.
Heres the function:
function extract_string( inputstr as string , pos as integer , delimiter as string )
local str as string
str = first token$( inputstr , delimiter )
if pos = 0
exitfunction first token$( str , "" )
endif
while n <= pos : inc n
str = next token$( delimiter )
if n = pos
exitfunction first token$( str , "" )
endif
endwhile
endfunction str
And in Action:
script01$ = "apple , orange , bomb"
script02$ = "Hello <Adam> and <Amy>"
script03$ = "1.3,0.95,0.8"
script04$ = "'A','B','C','D','E'"
name01$ = extract_string( script01$ , 0 , " , " )
name02$ = extract_string( script01$ , 1 , " , " )
name03$ = extract_string( script01$ , 2 , " , " )
extract01$ = extract_string( extract_string( script02$ , 1 , "<" ) , 0 , ">" )
extract02$ = extract_string( extract_string( script02$ , 2 , "<" ) , 0 , ">" )
x# = val(extract_string( script03$ , 0 , "," ))
y# = val(extract_string( script03$ , 1 , "," ))
z# = val(extract_string( script03$ , 2 , "," ))
letter01$ = extract_string( extract_string( script04$ , 0 , "," ) , 0 , "'" )
letter02$ = extract_string( extract_string( script04$ , 1 , "," ) , 0 , "'" )
letter03$ = extract_string( extract_string( script04$ , 2 , "," ) , 0 , "'" )
print name01$
print name02$
print name03$
print extract01$
print extract02$
print "axis: "+str$(x#,2)+","+str$(y#,2),","+str$(z#,2)
print letter01$
print letter02$
print letter03$
wait key
end
function extract_string( inputstr as string , pos as integer , delimiter as string )
local str as string
str = first token$( inputstr , delimiter )
if pos = 0
exitfunction first token$( str , "" )
endif
while n <= pos : inc n
str = next token$( delimiter )
if n = pos
exitfunction first token$( str , "" )
endif
endwhile
endfunction str
Enjoy
A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.