Intel® Fortran Compiler 18.0 Developer Guide and Reference

LEN

Inquiry Intrinsic Function (Generic): Returns the length of a character expression.

result = LEN (string [, kind])

string

(Input) Must be of type character; it can be scalar or array valued. (It can be an array of strings.)

kind

(Input; optional) Must be a scalar integer constant expression.

Results

The result is a scalar of type integer. If kind is present, the kind parameter of the result is that specified by kind; otherwise, the kind parameter of the result is that of default integer. If the processor cannot represent the result value in the kind of the result, the result is undefined.

The result has a value equal to the number of characters in string(if it is scalar) or in an element of string(if it is array valued).

Specific Name

Argument Type

Result Type

LEN 1

CHARACTER

INTEGER(4)

CHARACTER

INTEGER(8)

1The setting of compiler options specifying integer size can affect this function.

Example

Consider the following example:

  CHARACTER (15) C (50)
  CHARACTER (25) D

LEN (C) has the value 15, and LEN (D) has the value 25.

The following shows another example:

CHARACTER(11) STR(100)
INTEGER I
I = LEN (STR)  ! returns 11
I = LEN('A phrase with 5 trailing blanks.^^^^^')
               ! returns 37

See Also