$Arr Find: Difference between revisions
(→Syntax) |
m (add italics and links) |
||
Line 4: | Line 4: | ||
<p class="warn"><b>Note: </b>Most Sirius $functions have been deprecated in favor of Object Oriented methods. There is no direct OO equivalent for the $Arr_Find function because the OO methods emphasize the use of [[Collections]] over the use of arrays.</p> | <p class="warn"><b>Note: </b>Most Sirius $functions have been deprecated in favor of Object Oriented methods. There is no direct OO equivalent for the $Arr_Find function because the OO methods emphasize the use of [[Collections]] over the use of arrays.</p> | ||
<var>$Arr_Find</var> can be used to find an [[ | <var>$Arr_Find</var> can be used to find an [[Using variables and values in computation#%Variable arrays|array]] element with a specific value. | ||
==Syntax== | ==Syntax== | ||
<p class="syntax"><span class="term">%result</span> = $Arr_Find (array, value, minNum) | <p class="syntax"><span class="term">%result</span> = $Arr_Find (<span class="term">array, value, minNum</span>) | ||
</p> | </p> | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%result</th> | <tr><th>%result</th> | ||
<td>A numeric variable that is set to the array element number | <td>A numeric variable that is set to the array element number that contains the indicated value, or it is set to a -1 if the value was not found or if the array or <var class="term">minNum</var> is invalid.</td></tr> | ||
<tr><th>array</th> | <tr><th>array</th> | ||
<td>An array of string, float, or fixed values. This array must be a single dimensional array and must not be an array in an image.</td></tr> | <td>An array of string, float, or fixed values. This array must be a single dimensional array and must not be an array in an [[Images|image]].</td></tr> | ||
<tr><th>value</th> | <tr><th>value</th> | ||
Line 21: | Line 21: | ||
<tr><th>minNum</th> | <tr><th>minNum</th> | ||
<td>The lowest array element number to check. This argument can be used to skip the first " | <td>The lowest array element number to check. This argument can be used to skip the first <var class="term">n</var> array elements, where <var class="term">n</var> is a positive integer.</td></tr> | ||
</table> | </table> | ||
==Examples== | ==Examples== | ||
In the following example, % | In the following example, <code>%num</code> is set to 3: | ||
<p class="code">% | <p class="code">%fxarray is fixed array(5) | ||
%fxarray(1) = 2 | |||
% | %fxarray(2) = 3 | ||
% | %fxarray(3) = 5 | ||
% | %fxarray(4) = 8 | ||
% | %num= $Arr_Find(%fxarray,5) | ||
% | |||
</p> | </p> | ||
In the following example, <code>%num</code> is set to 5: | |||
In the following example, % | <p class="code">%starray is string len 20 array(6) | ||
<p class="code">% | %starray(1) = 'ONE' | ||
%starray(2) = 'TWO' | |||
% | %starray(3) = 'THREE' | ||
% | %starray(4) = 'FOUR' | ||
% | %starray(5) = 'ONE' | ||
% | %starray(6) = 'TWO' | ||
% | %num = $Arr_Find(%starray, 'ONE', 2) | ||
% | |||
% | |||
</p> | </p> | ||
Revision as of 15:56, 8 January 2018
Find value within array
Note: Most Sirius $functions have been deprecated in favor of Object Oriented methods. There is no direct OO equivalent for the $Arr_Find function because the OO methods emphasize the use of Collections over the use of arrays.
$Arr_Find can be used to find an array element with a specific value.
Syntax
%result = $Arr_Find (array, value, minNum)
%result | A numeric variable that is set to the array element number that contains the indicated value, or it is set to a -1 if the value was not found or if the array or minNum is invalid. |
---|---|
array | An array of string, float, or fixed values. This array must be a single dimensional array and must not be an array in an image. |
value | The value to be located in the array. If this value is found in multiple array elements, $Arr_Find always returns the first (lowest element number) array element containing this value. |
minNum | The lowest array element number to check. This argument can be used to skip the first n array elements, where n is a positive integer. |
Examples
In the following example, %num
is set to 3:
%fxarray is fixed array(5) %fxarray(1) = 2 %fxarray(2) = 3 %fxarray(3) = 5 %fxarray(4) = 8 %num= $Arr_Find(%fxarray,5)
In the following example, %num
is set to 5:
%starray is string len 20 array(6) %starray(1) = 'ONE' %starray(2) = 'TWO' %starray(3) = 'THREE' %starray(4) = 'FOUR' %starray(5) = 'ONE' %starray(6) = 'TWO' %num = $Arr_Find(%starray, 'ONE', 2)