[Gambas-user] Using strings like objects

Me adamnt42 at gmail.com
Sun Sep 23 11:26:52 CEST 2018


On Sun, 23 Sep 2018 09:27:13 +0200
Benoît Minisini <g4mba5 at gmail.com> wrote:

> 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
> 
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----

I think that is wonderful! Only one thing, we often have to search backwards in strings for various reasons, so
S.Reverse would be a great help.

regards
b


-- 
Me <adamnt42 at gmail.com>


More information about the User mailing list