I just knocked this up... It's probably not all that fast, but does what you need (I think):
// Project: stringtok
// Created: 2016-06-10
// Author: Conrad Brown
// set window properties
SetWindowTitle( "stringtok" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
Test$ = "HellotestMoo test Yeah! test woohoo test Works?"
do
print( GetStringToken3(Test$,"test",2))
Print( ScreenFPS() )
Sync()
loop
function GetStringToken3(st as string, de as string, tok as integer)
if tok <= (FindStringCount(st,de)+1)
wrk$ = st
tokstart = 0
`find the start of the token we want
if tok = 1
tokstart = 1
else
for t = 1 to tok-1
tokstart = tokstart + FindString(wrk$,de)+len(de)-1
wrk$ = mid(wrk$,FindString(wrk$,de)+len(de),len(wrk$)-(FindString(wrk$,de)+len(de)))
next t
inc tokstart
endif
` find the end of the token we want
tokend = FindString(wrk$,de)-1
` if it is the very last token in the string
if tokend = -1
tokend = len(st)-tokstart+1
endif
st = mid(st,tokstart,tokend)
else
` not enough tokens in the string
st = ""
endif
endfunction st
I hope it is useful to you.