TokenChars (StringTokenizer property): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
<span style="font-size:120%; color:black"><b>What are the token-delimiter characters?</b></span>
{{Template:StringTokenizer:TokenChars subtitle}}
[[Category:StringTokenizer methods|TokenChars property]]
<!--DPL?? Category:StringTokenizer methods|TokenChars property: What are the token-delimiter characters?-->
<!--DPL?? Category:System methods|TokenChars (StringTokenizer property): What are the token-delimiter characters?-->
<p>
TokenChars is a member of the [[StringTokenizer class]].
</p>


This readWrite property returns or sets the characters that are recognized as
This readWrite property returns or sets the characters that are recognized as
Line 14: Line 8:
(in which case it is treated as a non-delimiter character).
(in which case it is treated as a non-delimiter character).


===Syntax===
==Syntax==
  %string = %tok:TokenChars
{{Template:StringTokenizer:TokenChars syntax}}
 
  %tok:TokenChars = %string
===Syntax terms===
===Syntax terms===
<dl>
<dl>
Line 32: Line 24:


</dl>
</dl>
===Usage Notes===
==Usage notes==
<ul>
<ul>
<li>The TokenChars tokens are initially settable in the
<li>The TokenChars tokens are initially settable in the
Line 39: Line 31:
one of either the Quotes characters or the Spaces characters.
one of either the Quotes characters or the Spaces characters.
</ul>
</ul>
===Examples===
==Examples==


The statements in the sequence below tokenize the given equation:
The statements in the sequence below tokenize the given equation:
Line 65: Line 57:
     %tok:nextToken is )
     %tok:nextToken is )
</pre>
</pre>
==See also==
{{Template:StringTokenizer:TokenChars footer}}

Revision as of 19:54, 6 February 2011

Characters to be interpreted as tokens (StringTokenizer class)


This readWrite property returns or sets the characters that are recognized as token-delimiter characters, that is, as single-character delimiters that are also tokens themselves. As a delimiter, a token-delimiter character is a non-included boundary at the end or beginning of a token, unless the character is part of a quoted region (in which case it is treated as a non-delimiter character).

Syntax

%currentString = stringTokenizer:TokenChars stringTokenizer:TokenChars = newString

Syntax terms

%string
A string variable to contain the returned value of the current token-delimiter character(s) or to be set as the new value(s). The default value for a new tokenizer instance is a null. If you are setting TokenChars, each character in the string is a token character — that is, you may not separate characters — and no character may repeat (except for apostrophe, which may be doubled).
%tok
A StringTokenizer object variable.

Usage notes

  • The TokenChars tokens are initially settable in the New call that creates the tokenizer instance.
  • No character can be one of the TokenChars characters and also one of either the Quotes characters or the Spaces characters.

Examples

The statements in the sequence below tokenize the given equation:

    %tok = new(tokenchars='()=+')
    %tok:string = 'y = (x + 1)(x - 1)'
    repeat while not %tok:atEnd
       printText {~} is {%tok:nextToken}
    end repeat

The result is:

    %tok:nextToken is y
    %tok:nextToken is =
    %tok:nextToken is (
    %tok:nextToken is x
    %tok:nextToken is +
    %tok:nextToken is 1
    %tok:nextToken is )
    %tok:nextToken is (
    %tok:nextToken is x
    %tok:nextToken is -
    %tok:nextToken is 1
    %tok:nextToken is )

See also