Words (String function)

From m204wiki
Jump to navigation Jump to search

Sublist of list of words (String class)

[Introduced in Sirius Mods 7.9]

Words returns a substring of the method object string using word counts. The method returns a specified number of words, starting from a specified word and including consecutive following words.

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


%outString = string:Words( start, [count], [Spaces= string])

Syntax terms

%outStringThe returned substring of string. %outString contains as many words as count, including and continuing from word number start. As shown in the "Whitespace not collapsed" example, whitespace characters within the return result are not collapsed.
string The method object string, from which substring %outString is extracted.
start The number of the word in string that is the start of the extracted %outString. start must be greater than or equal to 1, which designates the first word. If start is greater than the number of words in string, the null string is returned.
count The number of words in string to extract to %outString. This is an optional argument; the default is to extract the rest of string starting at word number start. If count is greater than the number of words remaining in string starting with word number start, the remainder of the string starting at word number start is returned. This argument must be non-negative; if zero, 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. See the "Whitespace not collapsed" example.

Usage notes


Whitespace not collapsed

The following fragment:

printText {~='a!b@@@c':words(2, spaces='@!')}

produces this result:

'a!b@@@c':words(2, spaces='@!')=b@@@c

  • The output result contains exactly the selected input substring; multiple whitespace characters are not collapsed.


The following fragment:

printText {~='aa bb cc':words(2)}. printText {~='aa bb cc':words(1, 2)}. printText {~='aa bb cc':words(4, 1)}. printText {~='aa bb cc':words(3, 2)}. printText {~='aa bb cc':words(2, 0)}.

produces this result:

'aa bb cc':words(2)=bb cc. 'aa bb cc':words(1, 2)=aa bb. 'aa bb cc':words(4, 1)=. 'aa bb cc':words(3, 2)=cc. 'aa bb cc':words(2, 0)=.

See also