[Gambas-user] Using strings like objects
    Benoît Minisini 
    g4mba5 at gmail.com
       
    Sun Sep 23 09:27:13 CEST 2018
    
    
  
Hi,
Since last commit, I allowed strings to be used like objects.
This is not syntactic sugar, as it is entirely implemented in the 
interpreter.
So now, if S is a string, you can do the following:
S[N] to get the N-th character of the string. Beware! Contrary to string 
subroutines, the first character position is zero. It's like using the 
string as a character array.
S[N, L] is an equivalent of Mid$(S, N + 1, L).
S.Len returns the length of the string.
S[] only deals with byte position, it can't handle UTF-8.
That new syntax is slower than calling directly Mid$() and Len(), but I 
don't think we will notice the difference.
Maybe I will add a S.Max property to returns the length minus one, but I 
don't think I will implement all the string routines as object methods.
Tell me what you think about that.
-- 
Benoît Minisini
    
    
More information about the User
mailing list