Word (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Template:String:Word subtitle}}
{{Template:String:Word subtitle}}
<p></p>
<p></p>
Note that processing a string of words may be better accomplished with the <var>[[StringTokenizer class|StringTokenizer]]</var> class.
Note that processing a string of words may be better accomplished with the <var>[[StringTokenizer class|StringTokenizer]]</var> class.
Line 9: Line 8:
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%selectedWord</th><td><var>Word</var> returns the word selected by <var class="term">number</var> within the <var class="term">string</var> method object.
<tr><th nowrap>%selectedWord</th><td><var>Word</var> returns the word selected by <var class="term">number</var> within the <var class="term">string</var> method object.
</td></tr>
</td></tr>
<tr><th>string</th>
<tr><th>string</th>
Line 18: Line 17:
</td></tr>
</td></tr>
<tr><th><var>Spaces</var></th>
<tr><th><var>Spaces</var></th>
<td>A set of "whitespace" characters, that is, characters that separate words. The default is the blank character. If the null string is provided, the blank character is used as the whitespace character.
<td>This optional, [[Notation conventions for methods#Named parameters|name required]], argument is a set of "whitespace" characters, that is, characters that separate words. The default is the blank character. If the null string is provided, the blank character is used as the whitespace character.
</td></tr>
</td></tr>
</table>
</table>


==Usage notes==
==Usage notes==
<ul>
<li><var>Word</var> is the OO version of <var>[[$Lstr_Word]]</var>, although there
is one difference: <var>$Lstr_Word</var> allows a word number argument that is
less than 1 (and treats it the same as if 1 were specified).
<var>Word</var> does not allow a word number argument that is less than 1.
</ul>
==Examples==
==Examples==
The following fragment:
The following fragment:
Line 37: Line 43:
<ul>
<ul>
<li>[[List of StringTokenizer methods]]
<li>[[List of StringTokenizer methods]]
<li><var>[[Words (String function)|Words]]</var> - Sublist of list of words
<li><var>[[Words (String function)|Words]]</var>, which produces a word sublist from a list of words
<li><var>[[WordCount (String function)|WordCount]]</var> - Count words in list
<li><var>[[WordCount (String function)|WordCount]]</var>, which counts the words in a list
<li><var>[[WordNumberIn and WordNumberOf (String functions)|WordNumberIn and WordNumberOf]]</var> - Word number of "needle" word within "haystack" list of words
<li><var class="camel">[[WordNumberIn and WordNumberOf (String functions)|WordNumberIn and WordNumberOf]]</var>, which return the word number of a "needle" word within a "haystack" list of words
</ul>
</ul>
{{Template:String:Word footer}}
{{Template:String:Word footer}}

Latest revision as of 22:47, 3 September 2015

Select word from list of words (String class)

[Introduced in Sirius Mods 7.9]

Note that processing a string of words may be better accomplished with the StringTokenizer class.

Syntax

%selectedWord = string:Word( number, [Spaces= string])

Syntax terms

%selectedWordWord returns the word selected by number within the string method object.
string The list of words, from which the result word is selected.
number The number of the word to select from the string method object. The first word is word number 1. The value of this argument must be greater than or equal to 1. If number is greater than the number of words in string, the null string is returned.
Spaces This optional, name required, argument is a set of "whitespace" characters, that is, characters that separate words. The default is the blank character. If the null string is provided, the blank character is used as the whitespace character.

Usage notes

  • Word is the OO version of $Lstr_Word, although there is one difference: $Lstr_Word allows a word number argument that is less than 1 (and treats it the same as if 1 were specified). Word does not allow a word number argument that is less than 1.

Examples

The following fragment:

PrintText {~='Dasher**** Dancer**** Prancer****':Word(2)}. PrintText {~='Dasher**** Dancer**** Prancer****':Word(2, Spaces=' *)')}. PrintText {~='One more time':Word(4))}.

produces the following result:

'Dasher**** Dancer**** Prancer****':Word(2)=Dancer****. 'Dasher**** Dancer**** Prancer****':Word(2, Spaces=' *)')=Dancer. 'One more time':Word(4))=.

See also