SuivantPrec.Bas prec.BasNiv. sup.

7.2 Character Substrings 

The substring notation can be used to select any contiguous section of any character variable or array element. The characters in any string are numbered starting from one on the left: the lower bound cannot be altered as it can in arrays. A substring is selected simply by giving the first and last character positions of the extract. For example, with:
       CHARACTER METAL*10
       METAL = 'CADMIUM'
then 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).

Substring Rules 

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'
Then the substring 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.

SuivantPrec.Bas prec.HautNiv. sup.