Anyone using dot notation with strings?

Post

Posted
Rating:
#1 (In Topic #1086)
Regular
JumpyVB is in the usergroup ‘Regular’
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?

Code (gambas)

  1.   Dim TmpStr As String = "Benoît"
  2.   Print "String.Len() = " & String.Len(TmpStr) '6
  3.   Print "Len() = " & Len(TmpStr) '7
  4.   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…/comp/gb/_boxedstring/len).
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
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 <EMOJI seq="1f609" tseq="1f609">😉</EMOJI>
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
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

Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
 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
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Guru
cogier is in the usergroup ‘Guru’
But if I start typing .Len, then no such warning is shown on the help screen (/comp/gb/_boxedstring/len - Gambas Documentation).

I have added the same warning to the Wiki. This should show up in a day or 2.
Online now: No Back to the top
1 guest and 0 members have just viewed this.