get element from String$

Blitz3D Forums/Blitz3D Programming/get element from String$

similiar function I created, but slightly different useage - mine doesn't catch errors like a null index or null token, infact looking at it again now I'm not sure what would happen if the user put in a huge offset/index value that didn't exist in the input string.

; ===========================================
; == util_getToken$
; ==
; == takes a tokenised string And returns the
; == nth tokenised value. token can only be
; == 1 char long
; == If the first character is the same as the
; == token we assume that each value is surrounded
; == by a bracing set of tokens if the first char
; == is different to the token we assume each value
; == is seperated by 1 token
; == EXAMPLES
; ==			"classname" "value"
; ==			;test;;data;;stuff;
; ==			128,55,24
; ===========================================

Function util_getToken$(instring$,token$,offset)
	If Mid$(instring$,1,1)=token$ Then
		rollingOffset=1
		returnVar$=""
		For count=1 To offset
			start1=Instr(instring$,token$,rollingOffset)
			rollingOffset=start1+1
			end1=Instr(instring$,token$,rollingOffset)
			rollingOffset=end1+1
			endPos=end1-(start1+1)
			returnVar$=Mid$(instring$,start1+1,endPos)
		Next
		Return returnVar$
	Else
		endpos=0
		For count=1 To offset
			endold=endpos+1
			endpos=Instr(instring$,token$,endold)
			If count=offset Then
				Return Mid$(instring$,endold,endpos-endold)
			EndIf
		Next	
	EndIf
End Function