Locate (Stringlist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (syntax digram, tags and links)
Line 1: Line 1:
{{Template:Stringlist:Locate subtitle}}
{{Template:Stringlist:Locate subtitle}}


This method locates a specified string in a <var>stringlist</var>.


This method locates a specified string in a <var>Stringlist</var>. The <var>Locate</var> method returns the item number of the <var>Stringlist</var> item that contains the specified string, or it returns a 0 if no matching items are found.
The <var>Locate</var> method returns the item number of the <var>stringlist</var> item that contains the specified string, or it returns a 0 if no matching items are found.


==Syntax==
==Syntax==
Line 8: Line 9:
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%rc</th>
<tr><th>%itemnum</th>
<td>A numeric variable set to the item number of the first item in the '''%sl''' <var>Stringlist</var> that contains the search string, or it is set to a 0 if no items match the search criterion. items in '''%sl''' after the string has been inserted.</td></tr>
<td>A numeric variable which will be set to the item number of the first item in the <var class="term">sl</var> <var>stringlist</var> that contains the search target string, or it is set to a 0 if no items match the search criterion.</td></tr>
<tr><th>sl</th>
<tr><th>sl</th>
<td>A <var>Stringlist</var> object.</td></tr>
<td>A <var>Stringlist</var> object.</td></tr>
<tr><th>string</th>
<tr><th>string</th>
<td>The string to be located. This is a required argument, and it must be no longer than 255 bytes.</td></tr>
<td>The target <var class="term">string</var> 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, searching begins at the first item in the <var>Stringlist</var>. Not specifying the starting item number is subtly different from specifying a starting item number of 1 -- specifying 1 is an error if the <var>Stringlist</var> is empty, while no specification simply returns a 0.</td></tr>
<td>A number that indicates the item number at which the search is to begin. If this argument is not specified, searching begins at the first item in the <var>stringlist</var>. Not specifying the starting item number is subtly different from specifying a starting item number of 1 -- specifying 1 is an error if the <var>stringlist</var> is empty, while no specification simply returns a 0.</td></tr>
<tr><th>startcol</th>
<tr><th>startcol</th>
<td>A number that specifies the starting column of the range of columns in which the search string must be located. 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 in which the search string must be located. This is an optional argument, and it defaults to 1.</td></tr>
<tr><th>endcol</th>
<tr><th>endcol</th>
<td>A number that specifies the ending column of the range of columns in which the search string must be located. This is an optional argument, and it defaults to 6124. If '''caseflag''' is a non-zero integer, the width of this column range is reduced to a maximum of 256.</td></tr>
<td>A number that specifies the ending column of the range of columns in which the search string must be located. This is an optional argument, and it defaults to 6124. If <var class="term">caseflag<var> is a non-zero integer, the width of this column range is reduced to a maximum of 256.</td></tr>
<tr><th>caseflag</th>
<tr><th>caseflag</th>
<td>An indicator for case-insensitive comparisons. If this argument is a non-zero integer, the string comparisons use <var>Stringlist</var> item data translated to uppercase (so the search 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.</td></tr>
<td>An indicator for case-insensitive comparisons. If this argument is a non-zero integer, the string comparisons use <var>stringlist</var> item data is translated to uppercase (so the search 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.</td></tr>
</table>
</table>


==Usage notes==
==Usage notes==
<ul><li><var>Locate</var> returns a 0 if the indicated string is not found, and it cancels the request for all other errors.<li>The following code locates a string in columns 31 through 40 of <var>Stringlist</var> %list:
<ul><li><var>Locate</var> returns a 0 if the indicated string is not found, and it cancels the request for all other errors.<li>Although under <var class="product">Sirius Mods</var> Version 6.6 and later, <var>stringlist</var> items can be longer than 6124 bytes, <var>Locate</var> will only look for matches in the first 6124 bytes of any <var>stringlist</var> item.</ul>
 
==Examples==
The following code locates a string in columns 31 through 40 of <var>stringlist</var> %list:


<p class="code">%num = %list:locate('Eudaemonic', , 31, 40)
<p class="code">%num = %list:locate('Eudaemonic', , 31, 40)
</p>
</p>
<li>Although under <var class=product>Sirius Mods</var> Version 6.6 and later, <var>Stringlist</var> items can be longer than 6124 bytes, the <var>Locate</var> method will only look for matches in the first 6124 bytes of any <var>Stringlist</var> item.
</ul>


[[Category:Stringlist methods|Locate function]]
[[Category:Stringlist methods|Locate function]]

Revision as of 08:06, 26 January 2011

Locate next Stringlist item containing string (Stringlist class)


This method locates a specified string in a stringlist.

The Locate method returns the item number of the stringlist item that contains the specified string, or it returns a 0 if no matching items are found.

Syntax

%itemNum = sl:Locate( 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, searching begins at the first item in the stringlist. Not specifying the starting item number is subtly different from specifying a starting item number of 1 -- specifying 1 is an error if the stringlist is empty, while no specification simply returns a 0.
startcol A number that specifies the starting column of the range of columns in which the search string must be located. This is an optional argument, and it defaults to 1.
endcol A number that specifies the ending column of the range of columns in which the search string must be located. This is an optional argument, and it defaults to 6124. If caseflag is a non-zero integer, the width of this 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 stringlist item data is translated to uppercase (so the search 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 returns a 0 if the indicated string is not found, and it cancels the request for all other errors.
  • Although under Sirius Mods Version 6.6 and later, stringlist items can be longer than 6124 bytes, Locate will only look for matches in the first 6124 bytes of any stringlist item.

Examples

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

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