[Gambas-user] Indexing Strings?
T Lee Davidson
t.lee.davidson at gmail.com
Thu Feb 13 19:32:18 CET 2020
On 2/13/20 1:16 PM, Benoît Minisini wrote:
> 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.
>
Okay, good. I have updated the documentation. Please see if it needs any correction.
--
Lee
More information about the User
mailing list