WordCount (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
Line 7: Line 7:
==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>A numeric variable to contain the number of words in the <var class="term">string</var> method object.
<tr><th>%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 string that is 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>
Line 28: Line 31:
<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>

Revision as of 23:14, 5 November 2012

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