2.2.4 Character Substrings

A character substring is a contiguous segment of a character variable or character array element. It takes one of the following forms:

v ([e1]:[e2])
a (s [,s] . . . ) ([e1]:[e2])
v
Is a character variable name.
a
Is a character array name.
s
Is a subscript expression.
e1
Is a numeric expression specifying the leftmost character position of the substring.
e2
Is a numeric expression specifying the rightmost character position of the substring.

Character positions within a character variable or array element are numbered from left to right, beginning at one. For example, LABEL(2:7) specifies the substring beginning with the second character position and ending with the seventh character position of the character variable LABEL. If the CHARACTER*8 variable LABEL has a value of 'XVERSUSY', then the substring LABEL(2:7) has a value of VERSUS.

If the value of the numeric expression e1 or e2 is not of type integer, it is converted to an integer before use (any fractional parts are truncated).

The values of the numeric expressions e1 and e2 must meet the following conditions:

(1 .LE. e1) .AND. (e1 .LE. e2) .AND. (e2 .LE. len)
len
Is the length of the character variable or array element.

If e1 is omitted, Fortran assumes that e1 equals one. If e2 is omitted, Fortran assumes that e2 equals len. For example, NAMES(1,3)(:7) specifies the substring starting with the first character position and ending with the seventh character position of the character array element NAMES(1,3).


Previous Page Next Page Table of Contents