[bb] gettok$(word$,token,seperator) by skn3 [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:41

Previous topic - Next topic

BlitzBot

Title : gettok$(word$,token,seperator)
Author : skn3
Posted : 1+ years ago

Description : With this you just surply a string to test, which token you want, and the space charcter optional. Then it will return the token

EG
gettok$("token1 token2 token3",2," ")
would return "token2"


Code :
Code (blitzbasic) Select
Function gettok$(from$,which,space$=" ")
Local foundword=False
Local mode=False
Local current=0
Local maketok$=""
Local getchar$=""
For i=1 To Len(from$)
getchar$=Mid$(from$,i,1)
If foundword=False Then
If mode=False Then
If getchar$<>space$ Then
mode=True
current=current+1
End If
If current=which Then
foundword=True
maketok$=maketok$+getchar$
End If
Else
If getchar$=space$ Then
mode=False
End If
End If
Else
If getchar$=space$ Then
Exit
Else
maketok$=maketok$+getchar$
End If
End If
Next
Return maketok$
End Function

;some test examples
Print gettok$("hello, this is just a test",2,",")
Print gettok$("Testing 1 2 3",2)
Print ( Int(gettok$("/calc 50 + 65",2)) + Int(gettok$("/calc 50 + 65",4)) )


Comments : none...