String splitting to Arrays

BlitzMax Forums/BlitzMax Programming/String splitting to Arrays

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

In my module I have got 2 methods for splitting Strings and send them to an Array. I have made 2 functions out of them to share them with you.

The first one called Return_strip devides the string as often it finds the delivered ASCII code in the String.

The second one called Return_strip2 devides the string as long as the delivered _strip:string is. i.e: the stripstring is
" :" the main string will be divided two times.
("Load Map:Test.dat" will result in 1. "load" and 2. "Map:Test.dat" with the first function but with the second one you will get : 1."Load" 2."Map" 3."Test.Dat")


Strict

Local I:Int



Print "Return_strip2 : ('Load Map:Test.dat')"

Local Strip:String[]
Strip = Return_Strip2("Load Map:Test.dat"," :")
For I = 0 To Strip.length-1
Print I + " : " + Strip[I]
Next

Print "Return_strip  : ('Load Map:Test.dat')"

Local Strip2:String[]
Strip2 = Return_Strip("Load Map:Test.dat",32)
For I = 0 To Strip2.length-1
Print I + " : " + Strip2[I]
Next




Function Return_Strip2:String[](_String:String,_strip:String)

	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(Mid(_strip,I+1,1))
			If sp_p = - 1 Or I > _strip.length -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 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