Cold Help System: Programming: ColdC Reference Manual: Language Structure: Expressions: Operators: Index Operators


Indexing involves lookup in either a string, list, buffer and in some instances a dictionary. Depending upon the specific operator used indexing can return either the position of a desired element, or it can return the element at the specified position. There are two indexing operators, each performing one of these roles:

[]
in

The binary operator index-lookup (in) is used to find the position of an element. It may only be used with strings, lists and buffers. When used this operator will return an integer representing the position within the right side data where the left side specified element exists. If the specified element does not exist, a zero (0) is returned. Indexing is case-insensitive, when using strings. Example:

"C" in "abcdefg"
=> 3

The expression find and the functions stridx(), listidx() and bufidx() may also be used in finding the positional index of an element.

The index-retrieve operator ([]) is used to retrieve an element found within the data. It may be used with strings, lists, buffers and dictionaries. It is a binary operator, although its syntax is not as standard as others:

data expression[data expression]

The right data expression is used as the key to lookup within the left data expression. In all but the dictionary the right data expression must result in an integer, which represents the position in the right data expression to retrieve from. With a dictionary the right data expression may be any data type (see Dictionaries).


Operator Precedence | Index Operators | Arithmetic Operators | Assignments | Logical Operators | Conditional | List Splice Operator


the Cold Dark