WordCount (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Template:String:WordCount subtitle}}
{{Template:String:WordCount subtitle}}
<var>WordCount</var> returns the number of words in its method object string.
<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.
   
   
==Syntax==
==Syntax==
{{Template:String:WordCount syntax}}
{{Template:String:WordCount syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%number</th><td><var>WordCount</var> returns the number of words in the <var class="term">string</var> method object.
<tr><th nowrap>%number</th><td>A numeric variable to contain the number of words in the <var class="term">string</var> method object.
</td></tr>
</td></tr>
<tr><th>string</th>
<tr><th>string</th>
<td>The list of words to be counted.
<td>The string that is the list of words to be counted.
</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>WordCount</var> is the OO version of <var>[[$Lstr_Words]]</var>.
</ul>
==Examples==
==Examples==
The following fragment:
The following fragment:
<p class="code">PrintText {~="I'd like to buy the world a joke":WordCount}
<p class="code">PrintText {~="I'd like to buy the world a joke":WordCount}
</p>
</p>
produces the following result:
produces this result:
<p class="output">"I'd like to buy the world a joke":WordCount=8
<p class="output">"I'd like to buy the world a joke":WordCount=8
</p>
</p>
==See also==
==See also==
<ul>
<ul>
<li>[[List of StringTokenizer methods]]
<li>[[List of StringTokenizer methods]]
<li><var>[[Word (String function)|Word]]</var> - Select word from list of words
<li><var>[[Words (String function)|Words]]</var>, which produces a word sublist from a list of words
<li><var>[[Words (String function)|Words]]</var> - Sublist of list of words
<li><var>[[Word (String function)|Word]]</var>, which selects a word from a list of words
<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
<li><var>WordCount</var> is the OO version of <var>$Lstr_Words</var>.
</ul>
</ul>
{{Template:String:WordCount footer}}
{{Template:String:WordCount footer}}

Latest revision as of 23:00, 3 September 2015

Count words in list (String class)

[Introduced in Sirius Mods 7.9]

WordCount returns the number of words in its method object string.

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

Syntax

%number = string:WordCount[( [Spaces= string])]

Syntax terms

%numberA numeric variable to contain the number of words in the string method object.
string The string that is the list of words to be counted.
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

Examples

The following fragment:

PrintText {~="I'd like to buy the world a joke":WordCount}

produces this result:

"I'd like to buy the world a joke":WordCount=8

See also