$Index

From m204wiki
Jump to navigation Jump to search

Find position of one string within another

Note: Most $functions have been deprecated in favor of Object Oriented methods. The OO equivalents for the $Index function are the PositionIn and PositionOf functions.

$Index returns a number equal to the first position within the first string at which the second string appears.

Example 1

$INDEX ('OTHER', 'THE') equals 2 $INDEX ('SAME', 'SAME') equals 1

Example 2

If the second string is not contained in the first or is a null string, zero is returned:

$INDEX ('SAME', 'OTHER') equals 0 $INDEX ('SOME', 'SOMEMORE') equals 0 $INDEX ('ABC', ") equals 0

Example 3

This request uses $Index to separate the last name from a field containing a full name in the form "last name, first name":

BEGIN FIND.RECS: FIND ALL RECORDS FOR WHICH DATE OF BIRTH IS LESS THAN 19660000 END FIND FOR EACH RECORD IN FIND.RECS %LASTNAME = - $SUBSTR (FULLNAME, 1, - $INDEX (FULLNAME,',')-1) ADD LAST NAME = %LASTNAME . . .