User Tools

Site Tools


notes_on_zero_based_arrays.htm
Navigation:  Clarion.Net (Clarion#) > Clarion# Language Extensions > Clarion.NET FAQs > Language >====== Notes on Zero-based Arrays ====== Previous pageReturn to chapter overviewNext page

Common STRING functions, when used with the Clarion# language, now uses zero-based arrays where applicable.

Here is some example code that illustrates this behavior:

Example:

ns    STRING
cs    CLASTRING(26)
array BYTE,DIM(10,12)  !first dimension is 10 elements
 CODE
 ns = 'abcdefghijklmnopqrstuvwxyz'
 cs = ns
! all of the following are expected, at position zero is the first character
 i# = 0
 SUB(ns,i#,1)  !returns 'a'
 SUB(cs,i#,1)  !returns 'a'
 ns[i#]        !returns 'a' (slice)
 cs[i#]        !returns 'a' (slice)
 !the dimension starts at zero
 MAXIMUM(array,0)       ! so this returns 10 (zero is first dimension)
! but these functions return one (1) as the first “STEP”
INSTRING('a',ns,1,0)    ! we start search at 0 position and it returns STEP 1
INLIST('a','a','b','c') ! returns 1

Note that the behavior shown above is consistent. The arrays are all zero based, but the “step number” starts at 1. Stated another way, you can't have a zero step.

notes_on_zero_based_arrays.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1