String splitting to Arrays

BlitzMax Forums/BlitzMax Programming/String splitting to Arrays

Would be nice but it seems both needs 0 millisecs.

Tested with this code:


Local I:Int
Global time:Int
Global time2:Int
Global time3:Int


Print "Return_strip  : "
Local Strip2:String[]
time = MilliSecs()
Strip2 = Return_Strip("This is a longer test string that I am using to test this split string test thing",32)
Time2 = MilliSecs()
time3 = time2 - time

Print "needed time: " + time3

Rem
For I = 0 To Strip2.length-1
Print I + " : " + Strip2[I]
Next
End Rem

Print "Pertubatios :"

time = MilliSecs()
Local myList:TList = SplitString("This is a longer test string that I am using to test this split string test thing", " ")
Time2 = MilliSecs() 
time3 = time2 - time

Print "needed time: " + time3 
Rem
If myList Then
	For a$ = EachIn myList
		Print a$
	Next
EndIf
End Rem

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




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



Results :

1: 0
2: 0
3: 14 (last one was a test if my test is correct)