



Character Substrings
CHARACTER METAL*10 METAL = 'CADMIUM' |
METAL(1:3) has the value 'CAD' while METAL(8:8) has the value blank because
the value is padded out with blanks to its declared length.
Substrings must be at least one character long. They can be used in general in the
same ways as character variables. Continuing with the last example, the assignment
statement:
METAL(3:4) = 'ES'
will change the value of METAL to 'CAESIUM ' (with three blanks at the end, since
the total length stays at 10).
The parentheses denoting a substring must contain a colon: there may be an integer expression on either side of the colon. The first expression denotes the initial character position, the second one the last character position. Both values must be within the range 1 to LEN, where LEN is the length of the parent string, and the length of the resulting substring must not be less than one.
Although the colon must always be present, the two integer expressions are
optional. The default value for the first one is one, the default for the second is the
position of the last character of the parent string. Thus, staying with the last
example: METAL(:2) has the value 'CA' while METAL(7:) has the value 'M' with
three blanks.
With array elements the substring expression follows the sub-script expression, for example:
CHARACTER PLAY(30)*80 PLAY(10) = 'AS YOU LIKE IT' |
PLAY(10)(4:11) has the value 'YOU LIKE'. Substrings can be
used in expressions anywhere except in the definition of a statement function; they
can also be used on the left-hand side of an assignment statement, and can be also be
defined by input/output statements.