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).Anyone using dot notation with strings?
Anyone using dot notation with strings?
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?
- BruceSteers
- Posts: 1615
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Anyone using dot notation with strings?
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
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
If at first you don't succeed , try doing something differently.
BruceS
BruceS
Re: Anyone using dot notation with strings?
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
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
Have you ever noticed that software is never advertised using the adjective "spreadable".
- BruceSteers
- Posts: 1615
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Anyone using dot notation with strings?
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
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
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- cogier
- Site Admin
- Posts: 1129
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Anyone using dot notation with strings?
I have added the same warning to the Wiki. This should show up in a day or 2.But if I start typing .Len, then no such warning is shown on the help screen (https://gambaswiki.org/wiki/comp/gb/_boxedstring/len).