String splitting to Arrays

BlitzMax Forums/BlitzMax Programming/String splitting to Arrays

well, a better test would be to do it a thousand times:
Local I:Int
Global time:Int
Global time2:Int
Global time3:Int


Print "Return_strip  : "
Local Strip2:String[]
time = MilliSecs()
For Local a:Int = 1 To 1000
	Strip2 = Return_Strip("This is a longer test string that I am using to test this split string test thing",32)
Next
Time2 = MilliSecs()-time
Print "needed time: " + time2



Print "Pertubatios :"

time = MilliSecs()
'Local myList:TList
For Local b:Int = 1 To 1000
	Local myList:TList = SplitString("This is a longer test string that I am using to test this split string test thing", " ")
Next
Time2 = MilliSecs()-time
Print "needed time: " + time2


Print "Testloop : "
time = MilliSecs()
For i = 1 To 10000000
Next
Time2 = MilliSecs()-time
Print "needed time: " + time2




Function Return_Strip:String[](_String:String,_strip:Int)

	Local Text_Array : String[1]
	Local R_Text:String = _string
	Local i:Int = 0

	Repeat
		If R_Text.Length = 0 Then Exit
			Local sp_p:Int = R_Text.Find(Chr(_strip))
			If sp_p = - 1  Then
				Text_Array[I] = R_Text
				Exit
			End If
			Text_Array[I] = Left(R_Text,sp_p)
			R_Text = Right(R_Text,(R_text.Length - sp_p)-1)
			I:+1
			Text_Array = Text_array[..I+1]
	Forever
	
	Return Text_array	
	
End Function

Function SplitString:TList(inString:String, Delim:String)
	Local tempList : TList = New TList
	Local currentChar : String = ""
	Local count : Int = 0
	Local TokenStart : Int = 0
	
	If Len(Delim)<>1 Then Return Null
	
	inString = Trim(inString)
	
	For count = 0 Until Len(inString)
		If inString[count..count+1] = delim Then
			tempList.AddLast(inString[TokenStart..Count])
			TokenStart = count + 1
		End If
	Next
	tempList.AddLast(inString[TokenStart..Count])	
	Return tempList
End Function


This shows that mine is slower (which is what I suspected).
It is sometimes however handy to have the list functionality.

*EDIT*
Mine can be sped up slightly by not creating the list each loop (i.e. create it outside the loop and the assign to it inside).