INDEX intrinsic function
Standard: (F77) F90 F95 F2003 F2008
  Example Program


STRING : Character, any kind;
SUBSTRING : same type and kind as STRING;
BACK : Logical;
KIND : scalar Integer constant expression;

Result : Integer or Integer(Kind=KIND).


Searches STRING for an occurrence of SUBSTRING. If BACK is absent, or present with the value .FALSE., the search begins at the start of STRING; if BACK is present with the value .TRUE., the search begins at the end of STRING.

If there are no occurrences of SUBSTRING in STRING, the value zero is returned; otherwise, the result I has the property that STRING(I:I+LEN(SUBSTRING)-1)==SUBSTRING, and is the least such value for a forwards search and the greatest such value for a backwards search.

This means that if SUBSTRING is length zero, the result is equal to 1 for a forwards search and LEN(STRING)+1 for a backwards search.

Like many intrinsic functions, this is elemental; if any of STRING, SUBSTRING or BACK is an array, the result is also an array with the same shape and the operation being applied elementwise. Note that all array arguments must have the same shape.

In the unlikely event of the string being longer than 2GB, the KIND argument should be used to specify a 64-bit integer kind for the result.

CHARACTER type, SCAN intrinsic function, VERIFY intrinsic function.