I'm currently using the StringToHex() function below. But I think it should be much faster. Can you help?
The rules:
- Cross plattform
- Single Byte and Unicode capable
- In unicode mode, the unicode string must get converted to UTF8 first.
This is my attempth:
Code: Select all
EnableExplicit
; Copies string to single byte memory (make unicode to utf8)
Macro getSBStringCopy(orig, copy)
CompilerIf #PB_Compiler_Unicode
Protected copy.s = Space(StringByteLength(orig) * 2)
; make sure the result is null terminated
FillMemory(@copy, StringByteLength(copy), 0)
PokeS(@copy, orig, -1, #PB_UTF8)
CompilerElse
Protected copy.s = orig
CompilerEndIf
EndMacro
; Converts a string in hex notation at (each byte to a hex code)
Procedure.s StringToHex(Original.s)
Protected Ergebnis.s = ""
Protected x.i = 0
Protected Dummy.s = ""
getSBStringCopy(Original, sbOriginal)
For x.i = 1 To StringByteLength(sbOriginal.s)
Dummy.s = Dummy.s + RSet(Hex(PeekB(@sbOriginal + x - 1), #PB_Byte), 2, "0")
If Len(Dummy.s) > 500
Ergebnis.s = Ergebnis.s + Dummy.s
Dummy.s = ""
EndIf
Next
Ergebnis.s = Ergebnis.s + Dummy.s
ProcedureReturn Ergebnis.s
EndProcedure
Define Test.s = Space(100000)
Define start.i = ElapsedMilliseconds()
Define Result.s = StringToHex(Test.s)
Define ende.i = ElapsedMilliseconds()
MessageRequester("Test", "Needed " + Str(ende.i - start.i) + "ms")
EndThank you,
Kukulkan


