Substring Operators
Other operators are the [:] or [] substring operators, which operate on strings and binaries to extract or assign substrings or characters.
JADE string handling notation is listed in the following table. (The yield of the string operator notation, using a value of "Hello world" for string1, is given in the comment after the examples.)
Notation | Description |
---|---|
[n] |
String index, returning the single character at the position specified by the n value in the string; for example: |
char := string1[11]; // char = "d" |
|
[n:length] | Returns the substring from the position specified by the n value for the length specified by the length value in the string; for example: |
string2 := string1[5:4]; // string2 = "o wo" |
|
[n:end] | Returns the substring from the position specified by the n value to the end of the string; for example: |
string2 := string1[5:end] // string2 = "o world" |
The substring start and length values must be of type
For details about the use of subscript operators, see "Using Subscripts in Dictionaries and Arrays", in the following subsection.
Using Subscripts in Dictionaries and Arrays
The bracket ([]) subscripting operators enable you to assign values to and retrieve values from an array or a dictionary.
The code fragments in the following examples show the syntax of bracket subscripting operators for arrays and dictionaries.
stringArray[5] := "Five"; str := stringArray[5]; // str = "five" productDict[prodName] := prod; prod := productDict[prodName]; // obtain product at key prodName customerDict["Sid Who", "12 Any Avenue", date1] := cust; cust := customerDict["Sid Who", "12 Any Avenue", date1]; objArray[row - 1] := obj; name[int : 1] := ' '; str := "Hello$$$World"; write str; // outputs Hello$$$World str[6:3] := "***"; write str; // outputs Hello***World