I ported this Blitz function (that I made a while ago) to PB. It splits a string into several pieces (seperated by a deliminator of your choice) then gets a particular one. Really useful for things like 'plain English' protocols (HTTP for example).
Pretty fast too (I hope). The test I included does 1000000 iterations in 2.1 seconds. Enjoy
Code: Select all
Procedure.s tok(txt.s, delim.s, tok)
start = 1
l = Len(delim)
For a = 1 To tok
If a > 1
start = found + l
EndIf
found = FindString(txt, delim, start)
length = found - start
Next
ProcedureReturn Mid(txt, start, length)
EndProcedure
#NUMLOOPS = 1000000
st.s = ""
t1 = GetTickCount_()
For a = 1 To #NUMLOOPS
st = tok("string tokeniser test", " ", 2)
Next
MessageRequester("Result", Str(#NUMLOOPS) + " in " + Str(GetTickCount_() - t1) + "ms", 0)
