NextPosition (StringTokenizer property): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
(No difference)

Revision as of 21:48, 6 February 2011

Position of character at current tokenizing position (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

%currentNumber = stringTokenizer:NextPosition stringTokenizer:NextPosition = newNumber

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

See also