I came up with a quick alternative but would be nice if we had something similar native in purebasic.
Thank you very much
I believe I also saw someone requesting case sensitivity options. Sorry I didn't include them in this.
This would allow the user to be able to cache and/or do their own indexing.
Here is my speed comparison test and code.
x is summing all the value strings making sure the results between the original and new are the same.
Generating String for speed test
Testing Original
Test Complete: Results: x =501000500, time =35797 ms
x has been reset: x = 0
Starting New test:
Test Completex: Results: x =501000500, time =171 ms
reposted : fixed a bug
Code: Select all
; Sorry for the messiness in advance ;)
OpenConsole()
Structure StringField
*position
*StringAddress.UNICODE
*Seperator.UNICODE
size.i
delsize.i
complete.i
EndStructure
Macro SetupStringField(stringfieldobject,String,delimiter,start=0)
;stringfieldobject#\position = 0
stringfieldobject#\seperator = @delimiter#
stringfieldobject#\StringAddress = @String#
stringfieldobject#\position = start#
stringfieldobject#\complete = 0
stringfieldobject#\delsize = Len(delimiter#)*2
EndMacro
Macro NextStringField(stringfieldobject)
stringfieldobject#\position = stringfieldobject#\stringaddress
Repeat
If stringfieldobject#\stringaddress\u = stringfieldobject#\seperator\u
If stringfieldobject#\delsize > 2
If CompareMemory(stringfieldobject#\stringaddress,stringfieldobject#\seperator,stringfieldobject#\delsize)
StringFieldobject#\size = StringFieldobject#\StringAddress - stringfieldobject#\position
StringFieldobject#\StringAddress + stringfieldobject#\delsize
;StringFieldobject#\StringAddress + 2
Break
EndIf
Else
StringFieldobject#\size = StringFieldobject#\StringAddress - stringfieldobject#\position
StringFieldobject#\StringAddress + 2
Break
EndIf
ElseIf stringfieldobject#\stringaddress\u = 0
StringFieldobject#\size = StringFieldobject#\StringAddress - stringfieldobject#\position
stringfieldobject#\complete = stringfieldobject#\stringaddress
Break
EndIf
StringFieldobject#\StringAddress + 2
ForEver
EndMacro
Macro GetStringField(StringFieldobject)
PeekS(StringFieldobject#\position,StringFieldObject#\size/2)
EndMacro
Macro GetStringFieldAddress(StringFieldobject)
StringFieldObject#\position
EndMacro
Macro GetStringFieldEnd(StringFieldobject)
StringFieldObject#\complete
EndMacro
Macro GetStringFieldSize(StringFieldobject)
StringFieldobject#\size
EndMacro
Macro starttimer()
timer = GetTickCount_()
EndMacro
Macro checktimer()
GetTickCount_() - timer
EndMacro
Macro debugx(info)
PrintN(info#)
EndMacro
DisableDebugger
debugx("Generating String for speed test")
For i = 0 To 1000
string$ + Str(i) + "abc"
Next
debugx("")
debugx("Testing Original")
count = CountString(string$,"abc")
starttimer()
Repeatamount = 1000
For therepeat = 0 To Repeatamount
For i = 1 To count
x+Val(StringField(string$,i,"abc"))
Next
Next
old = checktimer()
debugx("Test Complete: Results: x =" + Str(x) + ", time =" + Str(old) + " ms")
debugx("")
x = 0
Debugx("x has been reset: x = "+Str(x))
debugx("Starting New test:")
del$ = "abc"
starttimer()
For therepeat = 0 To Repeatamount
SetupStringField(this.StringField,string$,del$)
While GetStringFieldEnd(this) = 0
NextStringField(this)
x+Val(GetStringField(this))
Wend
Next
newx = checktimer()
debugx("Test Completex: Results: x =" + Str(x) + ", time =" + Str(newx) + " ms")
debugx("")
debugx("Press Enter to Close")
Input()