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

Martin mbelmonte at belmotek.net
Tue Nov 10 10:08:45 CET 2020


Hi, i made some tests also.

the results was:

' The faster

Public Function BrianTrim(sRaw As String) As String
   Dim sOut As String
   sOut = Trim$(RegExp.Replace(sRaw, " {2,}+", " "))
   Return sOut
End

' The simplest, second place in velocity
Public Function ChristofTrim(sRaw As String) As String
   While InStr(sRaw, "  ")
     sRaw = Replace(sRaw, "  ", " ")
   Wend
   Return Trim$(sRaw)
End

The Brian 2nd version including pointers memory and libc seems to be 
more complex that the others solutions, anyway I don't know if is faster 
or not I don't test it.

Nice exercise.

Regards.

MB

On 10/11/20 5:57, Brian G wrote:
> Hi sorry to be late to the party, I included a project with all the methods mentioned. I have included my version of the remove spaces
> using alloc and pointers in gambas, it is faster if it is over 5000 characters.
> Run the project with profiling on.
>
> I have included the profiling output.
>
> Also I have optimized them all using fast unsafe.... eeek
> Thank You
> Brian G
>
> ----- Original Message -----
> From: "Christof Thalhofer" <chrisml at deganius.de>
> To: "Gambas mailing list" <user at lists.gambas-basic.org>
> Sent: Monday, November 9, 2020 8:38:16 PM
> Subject: Re: [Gambas-user] trimming extra spaces from within a string.
>
> Am 10.11.20 um 01:44 schrieb Bruce Steers:
>
>> So on further testing i'm finding the Repeat/Until method is the
>> forerunner  :)
> Did you see huge differences? On my computer both were nearly equal. But
> anyway, this job seems to be done.
>
> Alles Gute
>
> Christof Thalhofer
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201110/574b9557/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sample-trim-faster-0.0.1.tar.gz
Type: application/gzip
Size: 12114 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201110/574b9557/attachment.gz>


More information about the User mailing list