[Gambas-user] Using strings like objects
Fabien Bodard
gambas.fr at gmail.com
Sun Sep 23 15:42:19 CEST 2018
And sugards ;-)
S[5,3] = "toto"
s.replace("&1", "toto")
i = s.left(3)
etc.
s[s.instr("test"), s.len]
=
Mid(s, instr(s, "test"),len(s))
Le dim. 23 sept. 2018 à 11:27, Me <adamnt42 at gmail.com> a écrit :
> 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>
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
--
Fabien Bodard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20180923/0f1654a0/attachment.html>
More information about the User
mailing list