First time poster, long time user. Well, of Blitz. First time using BlitzMax and I see there is still no split function :o). Here is one for anyone interested. I needed it for a platform game I'm working on. Use. Enjoy. Etc.
Type TStringUtil
Field stringy:String
Method Split:Array(splitter:String)
Local sa:String[]
Local pos:Int = 1
Local lastpos:Int = 1
Local lastString:String
Local count:Int = 0
pos = stringy.Find(splitter, pos)
While pos < Len(stringy) And pos > 0
lastString = Mid(stringy, lastpos, (pos-lastpos)+1)
pos = pos + 1
lastpos = pos + 1
pos = stringy.Find(splitter, pos)
sa = sa[..count+1]
sa[count] = lastString
count = count + 1
Wend
sa = sa[..count+1]
sa[count] = Right(stringy, Len(stringy)-lastpos+1)
Return sa
End Method
Function Create:TStringUtil(s:String)
a:TStringUtil = New TStringUtil
a.stringy = s
Return a
End Function
End Type
You can used this sample bit of code here to get started:
t:TStringUtil = TStringUtil.Create("11,2,33,44")
Local s:String[]
s = t.Split(",")
Print s[1]
Cheers,
Sloan
Type TStringUtil
Field stringy:String
Method Split:Array(splitter:String)
Local sa:String[]
Local pos:Int = 1
Local lastpos:Int = 1
Local lastString:String
Local count:Int = 0
pos = stringy.Find(splitter, pos)
While pos < Len(stringy) And pos > 0
lastString = Mid(stringy, lastpos, (pos-lastpos)+1)
pos = pos + 1
lastpos = pos + 1
pos = stringy.Find(splitter, pos)
sa = sa[..count+1]
sa[count] = lastString
count = count + 1
Wend
sa = sa[..count+1]
sa[count] = Right(stringy, Len(stringy)-lastpos+1)
Return sa
End Method
Function Create:TStringUtil(s:String)
a:TStringUtil = New TStringUtil
a.stringy = s
Return a
End Function
End Type
You can used this sample bit of code here to get started:
t:TStringUtil = TStringUtil.Create("11,2,33,44")
Local s:String[]
s = t.Split(",")
Print s[1]
Cheers,
Sloan