[Gambas-user] Indexing Strings?
Benoît Minisini
g4mba5 at gmail.com
Thu Feb 13 19:16:57 CET 2020
Le 13/02/2020 à 18:47, T Lee Davidson a écrit :
> http://gambaswiki.org/wiki/lang/type/string states, "The first character
> of a string is numbered one, not zero." Yet, this code:
> Dim sText As String = "Hello World"
>
> Print sText[1] 'prints "e"
> Print sText[0] 'prints "H"
>
> appears to demonstrate that strings are indexed starting with 0.
> However, string functions seem to use a 1-based index.
>
> What's the reason for this discrepancy?
>
>
The array syntax was introduced recently for people who prefer it, so
the documentation is not up to date.
And array indexes start at 0. But string functions count from 1, because
of BASIC legacy.
Regards,
--
Benoît Minisini
More information about the User
mailing list