StringTokenizer (String function)

From m204wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Create a tokenizer using the method object string (String class)

[Introduced in Sirius Mods 7.8]

This method returns a new instance of a StringTokenizer object using the method string as the tokenizer string. It has three optional arguments that let you specify the delimiter characters that determine the tokens in the string that is being tokenized.

Syntax

%stringTokenizer = string:StringTokenizer[( [TokenChars= string], - [Spaces= string], - [Quotes= string], - [Separators= string])]

Syntax terms

%stringTokenizer A StringTokenizer object expression to contain the new object instance.
string The string to be tokenized.
TokenChars This name required string argument is a set of single-character token-delimiters (delimiters that are also tokens) that may be separated by whitespace characters.

TokenChars is an optional argument that defaults to a null string.

Spaces This name required string argument is a set of "whitespace" characters, that is, characters that separate tokens. Each of these characters is a "non-token delimiter," a delimiter that is not itself a token.

Spaces is an optional argument that defaults to a blank character.

Quotes This name required string argument is a set of quotation characters. The text between each disjoint pair of identical quotation characters (a "quoted region") is treated as a single token, and any delimiter characters (Quotes, Spaces, Separators, or TokenChars) within a quoted region are treated as non-delimiters.

Quotes is an optional argument that defaults to a null string.

Separators This name required string argument is a set of single characters that separate tokens. Each of these characters is a "non-token delimiter," a delimiter that is not itself a token.

Multiple Separators characters do not compress to a single separator (like Spaces characters).

Separators is an optional argument that defaults to a null string. It is available as of Sirius Mods version 7.8.

Usage notes

  • Do not confuse the StringTokenizer function, which creates a new object, with the String property of the StringTokenizer class, which only replaces the string to be tokenized (and resets the object to start tokenizing at the beginning), preserving various tokenizing properties such as Separators and Quotes.
  • A character may belong to at most one of the Spaces, Quotes, or TokenChars sets of characters.
  • If you are specifying Quotes, Spaces, Separators, or TokenChars characters, each character in the string is a member of the defined set — that is, you may not separate characters — and no character may repeat (except for apostrophe, which may be doubled).
  • A quoted region is not affected by the TokensToLower and TokensToUpper properties.

Examples

begin %tok is object stringtokenizer %tok = 'foo bar':stringTokenizer printText {~} is '{%tok:string}' repeat while not %tok:atEnd printText {~} is '{%tok:nextToken}' end repeat end

The result is:

%tok:string is 'foo bar' %tok:nextToken is 'foo' %tok:nextToken is 'bar'

See also

  • StringTokenizer New constructor