Item (Stringlist function): Difference between revisions
Jump to navigation
Jump to search
m (1 revision) |
m (→Usage notes) |
||
(25 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{Template:Stringlist:Item subtitle}} | {{Template:Stringlist:Item subtitle}} | ||
==Syntax== | ==Syntax== | ||
{{Template:Stringlist:Item syntax}} | {{Template:Stringlist:Item syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%string </th> | <tr><th>%string</th> | ||
<td>This longstring is to contain the contents of the | <td>This longstring is to contain the contents of the <var class="term">sl</var> item. </td></tr> | ||
<tr><th>sl </th> | <tr><th>sl</th> | ||
<td>A Stringlist object. </td></tr> | <td>A <var>Stringlist</var> object. </td></tr> | ||
<tr><th> | <tr><th>itemNum</th> | ||
<td>The number of the item in the | <td>The number of the item in the <var class="term">sl</var> <var>Stringlist</var>.</td></tr> | ||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul> | ||
<li>All errors in Item result in request cancellation. | <li>All errors in <var>Item</var> result in request cancellation. | ||
<li>Unlike the | <li>Unlike the <var>[[Item (Arraylist property)|Item]]</var> method for <var>[[Collections]]</var>, the <var>Item</var> method for <var>stringlists</var> is not settable. To set a new value for a <var>stringlist</var> item, use <var>[[Replace (Stringlist function)|Replace]]</var>.</ul> | ||
<li>The following loop uses the Item method to display the contents of a Stringlist: | |||
==Examples== | |||
<ol><li>The following loop uses the <var>Item</var> method to display the contents of a <var>Stringlist</var>: | |||
< | <p class="code">for %i from 1 to %list:count | ||
for %i from 1 to %list:count | print %list:item(%i) | ||
print %list:item(%i) | |||
end for | end for | ||
</ | </p> | ||
This could be accomplished much more easily with: | This could be accomplished much more easily with: | ||
< | <p class="code">%list:print | ||
%list:print | </p> | ||
</ | |||
< | <Li>Under <var class="product">Sirius Mods</var> Version 6.8 and later, the method name, <var>Item</var>, is not necessary on a <var>Stringlist</var> <var>Item</var> reference. For example, the previous program with <var>Item</var> references could be written as: | ||
< | <p class="code">for %i from 1 to %list:count | ||
for %i from 1 to %list:count | print %list(%i) | ||
print %list(%i) | |||
end for | end for | ||
</ | </p></ol> | ||
==See also== | |||
There are optimized methods available to retrieve just the first or just the last item in a <var>Stringlist</var>: | |||
<ul> | |||
<li><var>[[FirstItem (Stringlist function)|FirstItem]]</var> | |||
<li><var>[[LastItem (Stringlist function)|LastItem]]</var> | |||
</ul> | </ul> | ||
{{Template:Stringlist:Item footer}} | |||
Latest revision as of 17:43, 1 June 2012
Retrieve value of Stringlist item (Stringlist class)
Syntax
%string = sl:Item( itemNum)
Syntax terms
%string | This longstring is to contain the contents of the sl item. |
---|---|
sl | A Stringlist object. |
itemNum | The number of the item in the sl Stringlist. |
Usage notes
- All errors in Item result in request cancellation.
- Unlike the Item method for Collections, the Item method for stringlists is not settable. To set a new value for a stringlist item, use Replace.
Examples
- The following loop uses the Item method to display the contents of a Stringlist:
for %i from 1 to %list:count print %list:item(%i) end for
This could be accomplished much more easily with:
%list:print
- Under Sirius Mods Version 6.8 and later, the method name, Item, is not necessary on a Stringlist Item reference. For example, the previous program with Item references could be written as:
for %i from 1 to %list:count print %list(%i) end for
See also
There are optimized methods available to retrieve just the first or just the last item in a Stringlist: