Operator [ ] Foundation
Index operator (binary): accesses a specific element of an array, string, numeric or object.
<aArray>[<nElement,...>]
<aArray>[<nElement1>][<nElement2>] [...]
<nValue>[<nElement>]
<cString>[<nElement>]
<oObject>[<nElement>]
Individual elements of an array are accessed with the array operator. The expression returning the array must always precede the operator.
The numeric expression <nElement> must return an integer number not equal to zero in the range between the positive and negative number of array elements in the applicable dimension. A runtime error is generated if the value of <nElement> lies outside this range. If <nElement> has a positive value array elements are accessed from the beginning of the array. Negative values for <nElement> access an array from the end (the expression aArray[-1] == ATail(aArray) yields .T.). When <aArray> is an empty array the index operator cannot be used.
Extended functionality of the index operator
The index operator is not restricted to values of data type Array, but can also be used for character strings or numeric values.
Character
In case of character strings, the operator retrieves a single character of a string at the position <nElement> (see example below). This is much faster than retrieving a single character with the SubStr() function.
Numeric
When the operand has a numeric value, the operator tests if the bit at the position <nElement> is set. The result of this operation is .T. (true) when the bit is set, otherwise it is .F. (false). Individual bits of a numeric value can be manipulated by assigning .T. or .F. for the bit at the position <nElement>. The range for <nElement>extends from 1 to 32 when the operand is of numeric data type.
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.