INDEX

Platform

x64, Win32, .NET

Purpose

To get the starting position of a substring within a string.

Class

Elemental function.

Syntax

INTEGER FUNCTION INDEX(STRING, SUBSTRING [, BACK])
CHARACTER (LEN=*) STRING, SUBSTRING
LOGICAL BACK

Description

If BACK is omitted or has the value false then STRING is scanned from the beginning for the first occurrence of SUBSTRING. Zero is returned if all of SUBSTRING is not found or if LEN(SUBSTRING) = 0.

If BACK is true then scanning is from the end to find the last occurrence. Zero is returned if all of SUBSTRING is not found. LEN (STRING) + 1 is returned if LEN (SUBSTRING) = 0.

Return value

If SUBSTRING is found the result is a positive integer giving its position.

Example

INDEX('SALFORD', 'FORD') gives 4.
INDEX('FORTRAN', 'R', BACK=.TRUE.) gives 5.

 

 

Basket
Empty
 
Copyright © 1999-2024 Silverfrost Limited