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

Christof Thalhofer chrisml at deganius.de
Mon Nov 9 21:22:15 CET 2020


Am 09.11.20 um 20:09 schrieb Benoît Minisini:

> Still slower than needed. This is faster:
> 
> ------------------------------------------------------
> Repeat
>    OldLen = Len(Text)
>    Text = Replace(Text, "  ", " ")
> Until Len(Text) = OldLen
> ------------------------------------------------------

Yes! With a text with 314 K and a lot of multiple spaces trimmed 500
times your version wins by 3 ms!

2239 ms vs 2241 ms

> 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.

Slooow in my example test. 3211 ms.

(We lay a cloak of silence over the solution with Regexp.)

;-)

Alles Gute

Christof Thalhofer

-- 
Dies ist keine Signatur
-------------- next part --------------
A non-text attachment was scrubbed...
Name: regexp-compactspaces.png
Type: image/png
Size: 36908 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201109/a1517e18/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: split-join-compactspaces.png
Type: image/png
Size: 36674 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201109/a1517e18/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: benoit-compactspaces.png
Type: image/png
Size: 35399 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201109/a1517e18/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: while-wend-compactspaces.png
Type: image/png
Size: 35823 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201109/a1517e18/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201109/a1517e18/attachment-0001.sig>


More information about the User mailing list