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

Brian G brian at westwoodsvcs.com
Wed Nov 11 01:10:32 CET 2020


Fabian, for fun I adjusted your algorithm to use pointers not string
to try the fast unsafe with it.

Its made it 9 times slower than with a string.... wow unexpected!

like this
OutBuf As Pointer = Alloc(1000000)
Fast Unsafe Public Sub FabienTrim(sRaw As String) As String

  Dim s As String
  Dim hStream As File
  Dim bFirst As Boolean = True
  hStream = Open Memory Outbuf For Write
  ' 
  For i As Integer = 0 To Len(sRaw) - 1
    s = sRaw[i]
    If s = " " Then
      If Not bFirst Then
        Write #hStream, s
        bFirst = True
      Endif
    Else
      bFirst = False
      Write #hStream, s
    Endif
  Next
  
  Print "do close"
  Write #hstream, 0 As Byte
  Close #hStream
  s = String@(OutBuf)
  If bFirst Then Return Left(s, -1)
  Return s

End

Thank You
Brian G

----- Original Message -----
From: "Brian" <brian at westwoodsvcs.com>
To: "Gambas mailing list" <user at lists.gambas-basic.org>
Sent: Tuesday, November 10, 2020 3:37:26 PM
Subject: Re: [Gambas-user] trimming extra spaces from within a string.

Fabian it looks like a bug in the fast functions, interpreted for strings as streams. Is it worth reporting it as a bug?

Thank You
Brian G

----- Original Message -----
From: "Martin" <mbelmonte at belmotek.net>
To: "Gambas mailing list" <user at lists.gambas-basic.org>
Sent: Tuesday, November 10, 2020 3:34:56 PM
Subject: Re: [Gambas-user] trimming extra spaces from within a string.

On 10/11/20 23:45, Fabien Bodard wrote:
> Playing with code is not wasting time ... it's just fun:-P
>
> and finally we all learn a lot about weakness and strength of
> different structures of code

I agree !! :-)

Martin Belmonte


----[ http://gambaswiki.org/wiki/doc/netiquette ]----


More information about the User mailing list