This funcion determines the position in a string at which a given character sequence begins without regard to case.
IIDEX — Position
in CHRSTR where
KEY
begins. (Output)
If KEY occurs more than
once in CHRSTR,
the starting position of the first occurrence is returned. If KEY does not occur in
CHRSTR, then
IIDEX returns a
zero.
CHRSTR — Character string to be searched. (Input)
KEY — Character string that contains the key sequence. (Input)
Generic: IIDEX (CHRSTR, KEY)
Specific: The specific interface name is IIDEX.
Single: IIDEX (CHRSTR, KEY)
Routine IIDEX searches for a key string in a given string and returns the index of the starting element at which the key character string begins. It returns 0 if there is no match. The comparison is case insensitive. For a case-sensitive version, use the FORTRAN 77 intrinsic function INDEX.
If the length of KEY is greater than the length CHRSTR, IIDEX returns a zero.
This example locates a key string.
USE IIDEX_INT
USE UMACH_INT
IMPLICIT NONE
INTEGER NOUT
CHARACTER KEY*5, STRING*10
! Get output unit number
CALL UMACH (2, NOUT)
! Locate KEY in STRING
STRING = 'a1b2c3d4e5'
KEY = 'C3d4E'
WRITE (NOUT,99999) STRING, KEY, IIDEX(STRING,KEY)
!
KEY = 'F'
WRITE (NOUT,99999) STRING, KEY, IIDEX(STRING,KEY)
!
99999 FORMAT (' For STRING = ', A10, ' and KEY = ', A5, ' IIDEX = ', I2, &
/)
END
For STRING = a1b2c3d4e5 and KEY = C3d4E IIDEX = 5
For STRING = a1b2c3d4e5 and KEY = F IIDEX = 0
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |