StringTokenizer (String function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
No edit summary
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{Template:String:StringTokenizer subtitle}}
{{Template:String:StringTokenizer subtitle}}
This method returns a new instance of a <var>[[StringTokenizer class|StringTokenizer]] </var> object using the method string as the tokenizer string.
This method returns a new instance of a <var>[[StringTokenizer class|StringTokenizer]] </var> object using the method string as the tokenizer string.
It has three optional arguments that let you specify the delimiter characters
It has three optional arguments that let you specify the delimiter characters
Line 10: Line 9:
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%stringTokenizer</th>
<tr><th nowrap>%stringTokenizer</th>
<td>A <var>StringTokenizer</var> object expression to contain the new object instance. </td></tr>
<td>A <var>StringTokenizer</var> object expression to contain the new object instance. </td></tr>


Line 42: Line 41:
<ul>
<ul>
<li>Do not confuse the <var>StringTokenizer</var> <b>function</b>, which creates a new object, with the <var>[[String (StringTokenizer property)|String]]</var> property of the <var>StringTokenizer</var> <b>class</b>, which only replaces the string to be tokenized (and resets the object to start tokenizing at the beginning), preserving various tokenizing properties such as <var>[[Separators (StringTokenizer property)|Separators]]</var> and <var>[[Quotes (StringTokenizer property)|Quotes]]</var>.
<li>Do not confuse the <var>StringTokenizer</var> <b>function</b>, which creates a new object, with the <var>[[String (StringTokenizer property)|String]]</var> property of the <var>StringTokenizer</var> <b>class</b>, which only replaces the string to be tokenized (and resets the object to start tokenizing at the beginning), preserving various tokenizing properties such as <var>[[Separators (StringTokenizer property)|Separators]]</var> and <var>[[Quotes (StringTokenizer property)|Quotes]]</var>.
<li>A character may belong to at most one of the Spaces,
 
Quotes, or TokenChars sets of characters.
<li>A character may belong to at most one of the <var>Spaces</var>, <var>Quotes</var>, or <var>TokenChars</var> sets of characters.


<li>If you are specifying <var>Quotes</var>, <var>Spaces</var>, <var>Separators</var>, or <var>TokenChars</var> characters,
<li>If you are specifying <var>Quotes</var>, <var>Spaces</var>, <var>Separators</var>, or <var>TokenChars</var> characters,
each character in the string is a member of the defined set &mdash; that is, you may not separate characters &mdash; and no character
each character in the string is a member of the defined set &mdash; that is, you may not separate characters &mdash; and no character may repeat (except for apostrophe, which may be doubled).
may repeat (except for apostrophe, which may be doubled).


<li>A quoted region is not affected by the <var>[[TokensToLower (StringTokenizer property)|TokensToLower]]</var>
<li>A quoted region is not affected by the <var>[[TokensToLower (StringTokenizer property)|TokensToLower]]</var>
Line 72: Line 70:
%tok:nextToken is 'foo'
%tok:nextToken is 'foo'
%tok:nextToken is 'bar'
%tok:nextToken is 'bar'
</p>
</p>
==See also==
==See also==

Latest revision as of 21:56, 3 September 2015

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