next up previous contents index
Next: Substring Rules Up: Character Handling and Logic Previous: Character Facilities

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).



 

Helen Rowlands
8/27/1998