Some string enhancements...

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Some string enhancements...

Post by Michael Vogel »

I'd like to have a fast function which replaces

Code: Select all

s.s
:
s=Left(s,a)+Mid(s,a+n)
by

Code: Select all

RemoveChars(s,a,n)
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
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post 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
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post 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
Post Reply