Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'my variation on tokens in FreeBASIC allows dynamic length delimiters, but only one per call, passed via the "sep" parameter.
- '"index' is a string parameter to the token function that either is "ct" to return the amount of enumerated tokens, or otherwise validates as a numeric in order to return the token by index.
- function token(subject as string,sep as string=",",index as string="1") as string
- dim as string buffer,Ln
- dim as long o,t,i
- buffer=subject:t=0:i=val(index)
- if val(index)>0 then
- do
- t=t+1
- o=instr(1,buffer,sep):Ln=mid(buffer,o+len(sep)):buffer=mid(buffer,o+len(sep))
- loop until t=val(index)
- token=Ln
- elseif index="ct" then
- do
- t=t+1
- o=instr(1,buffer,sep):Ln=mid(buffer,o+len(sep)):buffer=mid(buffer,o+len(sep))
- loop until o=0
- token=str(t)
- end if
- end function
Add Comment
Please, Sign In to add comment