WordNumberIn and WordNumberOf (String functions)

From m204wiki
Revision as of 17:08, 27 April 2011 by Admin (talk | contribs) (1 revision)
Jump to navigation Jump to search

Word number of method object needle within argment list of words (String class) [introduced in Sirius Mods 7.9 βeta]


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

Syntax

%number = string:WordNumberIn( haystack, [Spaces= string])

Syntax terms

%number A variable to receive the number of the first occurrence of the needle word in the haystack list of words. If the word needle is not one of the words in haystack, %number is set to 0.
string The method object string. Depending upon whether the WordNumberIn or WordNumberOf function is being used, string may be either the:
  • search target needle, when called as WordNumberIn
  • the search space haystack, when called as WordNumberOf
haystack The list of words within which the needle is searched for.
needle The word which is searched for in the haystack.
Spaces 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 {~='aa bb cc':WordNumberOf('bb')} PrintText {~='bb':WordNumberIn('aa bb cc')}

produces the following result:

'aa bb cc':WordNumberOf('bb')=2 'bb':WordNumberIn('aa bb cc')=2

You can use WordNumberIn and Word as "quick and dirty" NamedArraylists:

%x = 'PA' %w = %x:WordNumberIn - ('MA PA MN') %s = ('Massachusetts Pennsylvania Minnesota'):Word(%w) Print 'Full state name:' And %s

However, as the number of words grows large, repeated use of WordNumberIn is less efficient than using a NamedArrayList.

See also