PeekToken (StringTokenizer function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
No edit summary
 
m (1 revision: CharacterMap, RandomNumberGenerator, StringTokenizer methods)
(No difference)

Revision as of 20:15, 16 December 2010

Value of next token in current tokenizer string, don't adva

PeekToken is a member of the 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 = %tok:PeekToken

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}