Hi an alternative using regular expression drops all the searches into an a array ready to parse took on a i3 350m cpu takes about 150 ms for 800k string 25000 | as delimiter
zebuddi.
Code: Select all
Procedure.s RegexFieldSeperator(sStringToSearch.s, sSeperator.s, Array sLine$(1))
Protected iAsciiNbr.i = Asc(Right(sSeperator,1))
; {-- add \ escape character
Select iAsciiNbr
Case 33, 34, 36 To 38, 40 To 43, 46, 47, 58, 60, 62, 63,94, 123 To 126
sSeperator = Left(sSeperator, Len(sSeperator)-1) + Chr(92) + Chr(iAsciiNbr)
EndSelect
; }
pattern$ = ".+?" + sSeperator
Protected iRegexAny . i = CreateRegularExpression(#PB_Any, pattern$, #PB_RegularExpression_AnyNewLine|#PB_RegularExpression_MultiLine), sReturnString.s, iNbr.i
If MatchRegularExpression(iRegexAny, sStringToSearch)
iNbr = ExtractRegularExpression(iRegexAny, sStringToSearch, sLine$())
FreeRegularExpression(iRegexAny)
ProcedureReturn Str(iNbr)
Else
ProcedureReturn "No Matches Found"
EndIf
EndProcedure
For i=1 To 25000 ; make a big string
For f = 1 To 25
q.s + Chr(Random(122, 97))
Next
fulltext$ + Str(i) + ". " + q + "|"
q = ""
Next
If CreateFile(0, GetTemporaryDirectory()+ " rubbish.txt") ; around 800k
WriteString(0, fulltext$)
CloseFile(0)
EndIf
Debug " Started"
Dim line$(0)
s = ElapsedMilliseconds()
Debug RegexFieldSeperator(fulltext$, "|", Line$()) ; search for all | and drop in an array
ms = ElapsedMilliseconds()-s
If Ms > 1000
Debug " took: " + FormatNumber(ms/1000) + " secs"
Else
Debug " took: " + FormatNumber(ms) + " ms"
EndIf
CallDebugger