Locate and LocateUp (Stringlist functions): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
Line 22: Line 22:
<td>The target string to be located. This is a required argument, and it must be no longer than 255 bytes.</td></tr>
<td>The target string to be located. This is a required argument, and it must be no longer than 255 bytes.</td></tr>
<tr><th>start</th>
<tr><th>start</th>
<td>A number that indicates the item number at which the search is to begin. If this argument is not specified:<ul><li>For <var>Locate</var>, searching begins at the first item in the <var class="term">sl</var> <var>Stringlist</var>.  Not specifying the starting item number is subtly different from specifying a starting item number of 1 &emdash; specifying 1 is an error if the <var>stringlist</var> is empty, while no specification simply returns a 0.<li>For <var>LocateUp</var>, searching begins at the last item in the <var class="term">sl</var> <var>Stringlist</var>.</td></tr>
<td>A number that indicates the item number at which the search is to begin. If this argument is not specified:<ul><li>For <var>Locate</var>, searching begins at the first item in the <var class="term">sl</var> <var>Stringlist</var>.  Not specifying the starting item number is subtly different from specifying a starting item number of 1 &emdash; specifying 1 is an error if the <var>stringlist</var> is empty, while no specification simply returns a 0.<li>For <var>LocateUp</var>, searching begins at the last item in the <var class="term">sl</var> <var>Stringlist</var>.</ul></td></tr>
<tr><th>startCol</th>
<tr><th>startCol</th>
<td>A number that specifies the starting column of the range of columns within which the target <var class="term">string</var> is searched for. This is an optional argument, and it defaults to 1.</td></tr>
<td>A number that specifies the starting column of the range of columns within which the target <var class="term">string</var> is searched for. This is an optional argument, and it defaults to 1.</td></tr>
Line 30: Line 30:
<td>An indicator for case-insensitive comparisons. If this argument is a non-zero integer, the string comparisons use <var>sl</var> <var>Stringlist</var> item data translated to uppercase (so the search target <var class="term">string</var> should be passed as an uppercase value). This is an optional argument, and it defaults to zero. If it is 1, the width of the searched column range is reduced to a maximum of 256.</td></tr>
<td>An indicator for case-insensitive comparisons. If this argument is a non-zero integer, the string comparisons use <var>sl</var> <var>Stringlist</var> item data translated to uppercase (so the search target <var class="term">string</var> should be passed as an uppercase value). This is an optional argument, and it defaults to zero. If it is 1, the width of the searched column range is reduced to a maximum of 256.</td></tr>
</table>
</table>
 
==Usage notes==
==Usage notes==
<ul>
<ul>

Revision as of 16:57, 6 April 2011

Locate next/previous Stringlist item that contains a string (Stringlist class)


Both these functions locate a specified string in a Stringlist. The difference between Locate and LocateUp is the direction of the search: Locate searches from the starting point in ascending item number order, while LocateUp searches from the starting point in descending item number order.

Both Locate and LocateUp return the item number of the Stringlist item that matches the input string, or they return 0 to indicate no matching items were found.

Syntax

%itemNum = sl:Locate( string, [[Start=] number], [[StartColumn=] number], - [[EndColumn=] number], [[CaseIndependent=] number], - [[ArbitraryQuote=] number])

%itemNum = sl:LocateUp( string, [[Start=] number], [[StartColumn=] number], - [[EndColumn=] number], [[CaseIndependent=] number], - [[ArbitraryQuote=] number])

Syntax terms

%itemNum A numeric variable which will be set to the item number of the first item in the sl Stringlist that contains the search target string, or it is set to a 0 if no items match the search criterion.
sl A Stringlist object.
string The target string to be located. This is a required argument, and it must be no longer than 255 bytes.
start A number that indicates the item number at which the search is to begin. If this argument is not specified:
  • For Locate, searching begins at the first item in the sl Stringlist. Not specifying the starting item number is subtly different from specifying a starting item number of 1 &emdash; specifying 1 is an error if the stringlist is empty, while no specification simply returns a 0.
  • For LocateUp, searching begins at the last item in the sl Stringlist.
startCol A number that specifies the starting column of the range of columns within which the target string is searched for. This is an optional argument, and it defaults to 1.
endCol A number that specifies the ending column of the range of columns within which the target string is searched for. This is an optional argument, and it defaults to 6124. If caseFlag is a non-zero integer, the width of the searched column range is reduced to a maximum of 256.
caseFlag An indicator for case-insensitive comparisons. If this argument is a non-zero integer, the string comparisons use sl Stringlist item data translated to uppercase (so the search target string should be passed as an uppercase value). This is an optional argument, and it defaults to zero. If it is 1, the width of the searched column range is reduced to a maximum of 256.

Usage notes

  • Locate and LocateUp return a 0 if the indicated string is not found, and cancel the request for all other errors.
  • While, under Sirius Mods Version 6.6 and later, Stringlist items can be longer than 6124 bytes long, these function will only look for matches in the first 6124 bytes of any Stringlist item.

Examples

  1. The following code locates a string in columns 31 through 40 of stringlist %list:

    %num = %list:locate('Eudaemonic', , 31, 40)

  2. The following code locates a string anywhere in a Stringlist %list item, searching backwards starting at item 100.

    %num = %list:locateUp('Vietnamerica', 100)

See also