Page 1 of 1
Some string enhancements...
Posted: Wed Apr 01, 2009 1:07 pm
by Michael Vogel
I'd like to have a fast function which replaces
by
I also ask, if something like #PB_String_InPlace could speed up ReplaceString() when the length of the searched string is longer than the text to replace...
Michael
Posted: Wed Apr 01, 2009 2:30 pm
by Hroudtwolf
Hi,
It is very easy to create such routines by yourself.
Code: Select all
Structure tChar
StructureUnion
c.c
s.s { 1 }
EndStructureUnion
EndStructure
Procedure.s RemoveChars ( sSource.s , nStarChar.i , nLength.i )
Protected *Source .tChar = @ sSource
Protected *CutPartStart = *Source + ( nStarChar * SizeOf ( tChar ) )
Protected *CutPartEnd = *CutPartStart + ( nLength * SizeOf ( tChar ) )
Protected sTemp .s
If Not *Source
ProcedureReturn sSource
EndIf
While *Source\c
If *Source < *CutPartStart Or *Source => *CutPartEnd
sTemp + *Source\s
EndIf
*Source + SizeOf ( tChar )
Wend
ProcedureReturn sTemp
EndProcedure
Debug RemoveChars ( "Hello world" , 9 , 1 )
Debug RemoveChars ( "Feel the pure power" , 10 , 5 )
Regards
Wolf
Posted: Wed Apr 01, 2009 3:35 pm
by Michael Vogel
Thanks Hroudtwolf,
you're right - quite a lot of functions are simple to implement (like the integer functions abs, min, max, signum etc.), other things could be more difficult (e.g. allow the #PB_String_NoCase also in FindString)...
But using selfmade functions means also (slightly) larger source codes and tons of different implementations (and incompatibilities) of the "same" functions.
I must admit, that my functions won't be useful in a huge number of programs, so they just should be kept on the whishlist :roll:
Michael