Sets are implicitly ordered and you may index into them to access individual elements. Square brackets are used to specify the element number to access. The first element is number one (1).
MySet := [5,4,3,2,1]; ReverseNum := MySet[2]; //indexing to MySet's element number 2, //so ReverseNum contains the value 4
Strings (Character Sets) may also be indexed to access individual or multiple contiguous elements within the set of characters (a string is treated as though it were a set of 1-character strings). An element number within square brackets specifies an individual character to extract.
MyString := 'ABCDE'; MySubString := MyString[2]; // MySubString is 'B'
Substrings may be extracted by using two periods to separate the beginning and ending element numbers within the square brackets to specify the substring (string slice) to extract. Either the beginning or ending element number may be omitted to indicate a substring from the beginning to the specified element, or from the specified element through to the end.
MyString := 'ABCDE'; MySubString1 := MyString[2..4]; // MySubString1 is 'BCD' MySubString2 := MyString[ ..4]; // MySubString2 is 'ABCD' MySubString3 := MyString[2.. ]; // MySubString3 is 'BCDE'