[Gambas-user] trimming extra spaces from within a string.

Benoît Minisini g4mba5 at gmail.com
Mon Nov 9 20:09:37 CET 2020


Le 09/11/2020 à 18:30, Christof Thalhofer a écrit :
> But this works:
> 
> --------------------------------------------------
>    While InStr(Text, "  ")
>        Text = Replace(Text, "  ", " ")
>    Wend
> 
>    Return Trim(Text)
> --------------------------------------------------
> 
> And it's about three times faster than Tobi's idea.
> 
> Alles Gute
> 
> Christof Thalhofer
> 

Still slower than needed. This is faster:

------------------------------------------------------
Repeat
   OldLen = Len(Text)
   Text = Replace(Text, "  ", " ")
Until Len(Text) = OldLen
------------------------------------------------------

Or one can try:

------------------------------------------------------
Text = Split(Text, " ", "", True).Join(" ")
------------------------------------------------------

Its speed relative to the previous solution depends on the length of 
Text and how many spaces there are in it.

Regards,

-- 
Benoît Minisini


More information about the User mailing list