The author of recent topic has requested for high performance -- and there is one cool and ultraoptimized here: http://www.purebasic.fr/english/viewtop ... 12&t=65159.
However, I found the ASM code too long and unhandy to use.
So there is another example, more "highlevel" ^^
It is also done similar to VB6 string split function.
Code: Select all
EnableExplicit
; 2016 (c) Lunasole
; equivalent of VB6 Split()
; sOut$: array to receive output
; String$: string to split
; Delimiter$: a sequence of chars to split String$ by
; Limit: a maximum number of results, if set, then last item of array contains all data over Limit
; RETURN: number of Delimiter$ inside of String$ [also it is size of sOut$ array]
Procedure SplitS(Array Out$(1), String$, Delimiter$, Limit = -1, Mode = #PB_String_CaseSensitive)
Protected nC, mPos, lPos = 1, nDelimLen = Len(Delimiter$)
Repeat
mPos = FindString(String$, Delimiter$, lPos, Mode)
If ArraySize(Out$()) < nC
ReDim Out$(nC + 10240) ; enlarge your array for just $2800 :3
EndIf
If mPos And (Limit = -1 Or nC < Limit)
Out$(nC) = Mid(String$, lPos, (mPos - lPos))
lPos = mPos + nDelimLen
nC + 1
Else
Out$(nC) = Mid(String$, lPos)
Break
EndIf
ForEver
ReDim Out$(nC) ; trim output array
ProcedureReturn nC
EndProcedure
; equivalent of VB6 Join()
; sOut$: array to receive output
; RETURN: string containing all array items
Procedure$ JoinS(Array In$(1), Delimiter$ = "")
Protected sOut$, nC, nCMax = ArraySize(In$())
For nC = 0 To nCMax
If Not nC = nCMax
sOut$ + In$(nC) + Delimiter$
Else
sOut$ + In$(nC)
EndIf
Next
ProcedureReturn sOut$
EndProcedure
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Dim T$(0) ; output array
Debug "RETURN: " + SplitS(T$(), "Macross: do you remember love?", " ")
Debug "======="
Define t
For t = 0 To ArraySize(T$())
Debug t$(t)
Next t