NextPosition (StringTokenizer property)

From m204wiki
Revision as of 02:54, 16 December 2010 by 198.242.244.228 (talk) (→‎Usage Notes)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Position of character at current tokenizing position

NextPosition is a member of the StringTokenizer class.

This readWrite property returns or sets the tokenizing position, the position of the character from which the parsing of the next token begins. Unless you explicitly set it otherwise, the tokenizing position is the position that follows the (last) character in the value returned by the most recent call of NextToken, FindToken, or NextChar.

Syntax

  %pos = %tok:NextPosition
  %tok:NextPosition = %pos

Syntax terms

%pos
A numeric variable to contain the returned value of the current tokenizing position. The default value is 1.
%tok
A StringTokenizer object variable.

Usage Notes

  • The CurrentTokenPosition property returns the position of the initial character in the current token. Setting NextPosition does not advance the current token position.
  • To advance the current token position a single character, you can use NextChar. If a NextChar function call immediately follows a NextPosition call, NextChar identifies the character whose position is the value of NextPosition.
  • If you reset NextPosition, the value returned by your next NextToken, FindToken, SkipTokens, or NextChar call will be based on the reset NextPosition value. The NextPosition value is entirely independent from the CurrentTokenPosition value, and vice versa. Both properties can be set to arbitrary locations in the tokenization string.

Examples

In the following request fragment, NextToken calls retrieve the first three tokens in the string, then NextPosition is explicitly set back to the second character in the string, from which the next token is determined:

    %tok is object stringTokenizer
    %tok = new
    %tok:string = 'This is the nextPosition example.'
    printText {~} is {%tok:nextToken}
    printText {~} is {%tok:nextToken}
    printText {~} is {%tok:nextToken}
    printText {~} is {%tok:nextPosition}
    %tok:nextPosition = 2
    printText {~} is {%tok:nextToken}
    printText {~} is {%tok:nextPosition}

The result is:

    %tok:nextToken is This
    %tok:nextToken is is
    %tok:nextToken is the
    %tok:nextPosition is 12
    %tok:nextToken is his
    %tok:nextPosition is 5