Interestingly, a self-written loop is faster than ReplaceString(, #PB_String_InPlace).
However, this self-written function only works for single character replacement.
Code: Select all
CompilerIf #PB_Compiler_Debugger
CompilerError "No Debugger!!!!!!!!!!"
CompilerEndIf
Procedure ReplaceChar(*String.Character, CharToSearch.c, CharToReplace.c)
If *String = 0
ProcedureReturn
EndIf
While *String\c
If *String\c = CharToSearch
*String\c = CharToReplace
EndIf
*String + SizeOf(Character)
Wend
EndProcedure
OpenConsole()
Define Time.q, Time1.q, Time2.q
Define String.s = ReplaceString(Space(10000), " ", "Abc")
Time = ElapsedMilliseconds()
For I = 1 To 1000
ReplaceString(String, "A", "a", #PB_String_InPlace)
ReplaceString(String, "a", "A", #PB_String_InPlace)
Next
Time1 = ElapsedMilliseconds() - Time
Time = ElapsedMilliseconds()
For I = 1 To 1000
ReplaceChar(@String, Asc("A"), Asc("a"))
ReplaceChar(@String, Asc("a"), Asc("A"))
Next
Debug String
Time2 = ElapsedMilliseconds() - Time
PrintN("ReplaceString: " + Time1 + " ms")
PrintN("ReplaceChar: " + Time2 + " ms")
Input()
Matheos wrote: Wed Jan 28, 2026 5:04 pm
Therefore, as the user moves around the data with PgUp/PgDn/Home/End and so on, we have to convert the control characters into a displayable character, normally 149 which is a dot, so the user can identify the characters that must not be changed or overwritten :
Code: Select all
ReplaceString(Params.s, Chr(60251), Chr(149), #PB_String_InPlace)
You can replace this function and you will gain speed, instead of loosing time.
ChrisR wrote: Wed Jan 28, 2026 7:28 pm
If used with ReplaceChar(@Test$, 'o', ''), the length needs to be recalculated with PeekS