Page 1 of 1

Anyone using dot notation with strings?

Posted: Saturday 9th September 2023 5:42am
by JumpyVB
If I declare a String and ask for it's length in dot notation, the ascii version of the function is used - I find this unexpected! What's the logic behind this? Is the reason historical and related to backwards compatibility?
  Dim TmpStr As String = "Benoît"
  Print "String.Len() = " & String.Len(TmpStr) '6
  Print "Len() = " & Len(TmpStr) '7
  Print ".Len = " & TmpStr.Len '7 !!?? I would have expected the UTF8-version of the len function to be used here. 
If I start typing .Left on gambas code editor, then a help window will pop up (http://gambaswiki.org/wiki/lang/left) stating the following: "This function only deals with ASCII strings. To manipulate UTF-8 strings, use the String.Left class." But if I start typing .Len, then no such warning is shown on the help screen (https://gambaswiki.org/wiki/comp/gb/_boxedstring/len).

Re: Anyone using dot notation with strings?

Posted: Saturday 9th September 2023 10:07pm
by BruceSteers
Yeah if you want to deal with non ASCII strings use String class static methods.

Len(TmpStr) is not a static gb.util/String.class method it's a built in function like Mid() and InStr().

If you think something should be added to a wiki page ,,, add it 😉

Re: Anyone using dot notation with strings?

Posted: Sunday 10th September 2023 6:55am
by thatbruce
I believe that Bruce is trying to say that declaring a variable as a String is not the same as using the String class even though it is in the gb component.'
The gb.String class is a set of static utility functions to specifically handle UTF character strings, a String variable is a "normal" ASCII string.
Since gb.String is essentially a static "class" i.e. it has no visible attributes, you cannot declare an object of that type, as is clearly indicated by the "This class is static." comment in the wiki.
I see no need for any changes to the wiki.
hth
bruce

Re: Anyone using dot notation with strings?

Posted: Thursday 25th April 2024 11:02am
by BruceSteers
I guess it comes down to Len() being a built in function and String.Len() being in the "handler of utf-8 strings" String.class from gb.util

With your logic then theoretically also Mid() and InStr(), etc would be expected to work UTF-8 strings too?

But no I think it makes sense.

As it stands Mid(), InStr(), Len(), etc are all for plain ascii
String.Mid(), String.InStr(), String.Len(), etc are all for UTF-8

Respects

Re: Anyone using dot notation with strings?

Posted: Thursday 25th April 2024 2:57pm
by cogier
But if I start typing .Len, then no such warning is shown on the help screen (https://gambaswiki.org/wiki/comp/gb/_boxedstring/len).
I have added the same warning to the Wiki. This should show up in a day or 2.