In any context where you refer to a character variable, you can refer instead to a substring (a sequential subset of the characters in that variable). For example, if a variable named myVar has the value is "ABCD", you can refer to "BC", the second and third characters, as myVar[2:3].
In addition, you can specify a substring on the left side of an assignment statement if the target substring has a fixed length. The substring area is padded with blanks if the source is shorter than the substring, and the source text is truncated if it is longer than the substring.
If toIndex is greater than fromIndex and both numbers are valid, the substring is an empty string.
The value of either index represents a byte position unless textVariable is a DBCHAR or UNICODE type. In that case, the value represents a double-byte character position.
When textVariable is a string (not limited length), the value of the index is between 1 and the length of the string.
When textVariable is a limited-length string, the value of the index is between 1 and the length you specified in the variable declaration. If there are no characters at the specified positions, the contents of the target substring depend on the target type. If the target type is STRING, the result is an empty string; otherwise the target is padded with blanks.
Count from the leftmost character, even if you are working with a bidirectional language such as Arabic or Hebrew.
limited string(20); s string; limited = "123456789"; s = limited[11:12]; // No error, and value of s is "" (an empty string). s = limited[8:12]; // No error, and value of s is "89". limited = s[8:12]; // Error because s has no length limit. // The last valid position is the one with the last character.
limited string(20) = "123456789"; s string = "abc"; limited[12:14] = s; // no error; value of limited becomes "123456789 abc":