Code archives/Algorithms/gettok$(word$,token,seperator)

This code has been declared by its author to be Public Domain code.

Download source code

gettok$(word$,token,seperator) by skn32002
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"
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.

Code Archives Forum