$Index: Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Automatically generated page update)
 
No edit summary
Line 1: Line 1:
<p>$INDEX compares two character strings and returns a number equal to the first position within the first string at which the second string appears. </p>
{{DISPLAYTITLE:$Index}}
<span class="pageSubtitle">Find position of one string within another</span>
 
<p class="warn"><b>Note: </b>Most $functions have been deprecated in favor of Object Oriented methods. The OO equivalents for the <var>$Index</var> function are the [[PositionIn and PositionOf (String functions)|PositionIn and PositionOf]] functions.</p>
<p><var>$Index</var> returns a number equal to the first position within the first string at which the second string appears. </p>
<b>Example 1</b>
<b>Example 1</b>
<p class="code">$INDEX ('OTHER', 'THE') equals 2
<p class="code">$INDEX ('OTHER', 'THE') equals 2
Line 11: Line 15:
</p>
</p>
<b>Example 3</b>
<b>Example 3</b>
<p>This request uses $INDEX to separate the last name from a field containing a full name in the form "last name, first name":</p>
<p>This request uses <var>$Index</var> to separate the last name from a field containing a full name in the form "last name, first name":</p>
<p class="code">BEGIN
<p class="code">BEGIN
FIND.RECS: FIND ALL RECORDS FOR WHICH
FIND.RECS: FIND ALL RECORDS FOR WHICH

Revision as of 17:21, 26 April 2014

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 . . .