PeekToken (StringTokenizer function): 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>Value of next token in current tokenizer string, do not advance</b></span>
{{Template:StringTokenizer:PeekToken subtitle}}
[[Category:StringTokenizer methods|PeekToken function]]
<!--DPL?? Category:StringTokenizer methods|PeekToken function: Value of next token in current tokenizer string, don't adva-->
<!--DPL?? Category:System methods|PeekToken (StringTokenizer function): Value of next token in current tokenizer string, don't adva-->
<p>
PeekToken is a member of the [[StringTokenizer class]].
</p>


This method returns the string value of
This method returns the string value of
Line 21: Line 15:
The delimiters can be modified by the [[Spaces (StringTokenizer property)|Spaces]],
The delimiters can be modified by the [[Spaces (StringTokenizer property)|Spaces]],
[[Quotes (StringTokenizer property)|Quotes]], and [[TokenChars (StringTokenizer property)|TokenChars]] properties.
[[Quotes (StringTokenizer property)|Quotes]], and [[TokenChars (StringTokenizer property)|TokenChars]] properties.
===Syntax===
==Syntax==
  %string = %tok:PeekToken
{{Template:StringTokenizer:PeekToken syntax}}
===Syntax terms===
===Syntax terms===
<dl>
<dl>
Line 31: Line 25:


</dl>
</dl>
===Usage Notes===
==Usage notes==
<ul>
<ul>
<li>If the value of [[AtEnd (StringTokenizer function)|AtEnd]] is <tt>True</tt>,
<li>If the value of [[AtEnd (StringTokenizer function)|AtEnd]] is <tt>True</tt>,
Line 46: Line 40:
does ''not'' become the current token.
does ''not'' become the current token.
</ul>
</ul>
===Examples===
==Examples==


The following sequence of printText statements display,
The following sequence of printText statements display,
Line 57: Line 51:
     printText {%tok:peekToken}
     printText {%tok:peekToken}
</pre>
</pre>
==See also==
{{Template:StringTokenizer:PeekToken footer}}

Revision as of 19:54, 6 February 2011

Value of next token in current tokenizer string, do not advance (StringTokenizer class)


This method returns the string value of the next token forward in the current tokenizer string. The next token parsing begins from the tokenizing position, which is the value returned by NextPosition.

When the next token is determined, PeekToken does not advance the tokenizing position, which remains what it was when PeekToken was called.

The delimiters that are involved in determining the tokens are set initially by the New method that instantiates the StringTokenizer object. The delimiters can be modified by the Spaces, Quotes, and TokenChars properties.

Syntax

%string = stringTokenizer:PeekToken Throws MismatchedQuote, OutOfBounds

Syntax terms

%string
A string variable to receive the value of the current token.
%tok
A StringTokenizer object variable.

Usage notes

  • If the value of AtEnd is True, issuing PeekToken is invalid and cancels the request.
  • The NextToken and FindToken functions return the next token and advance the tokenizing position to the character or position following that token. SkipTokens similarly advances the tokenizing position, but it returns no value. After a successful execution of NextToken, FindToken, or SkipTokens, the token located becomes the current token. This is not true for PeekToken: after it completes successfully, the token located does not become the current token.

Examples

The following sequence of printText statements display, respectively, example, example, and example, showing that the tokenizing position does not move after PeekToken completes:

    %tok:string = 'example of peekToken'
    printText {%tok:peekToken}
    printText {%tok:peekToken}
    printText {%tok:peekToken}

See also