NextPosition (StringTokenizer property)

From m204wiki
Jump to navigation Jump to search

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. Its initial value is 1.

The tokenizing position depends on the methods that precede it. Each call of NextToken, FindToken, or NextChar, for example, moves the tokenizing position to the position that follows the (last) character in the value returned by these methods. PreviousChar moves the tokenizing position to the preceding character, and SkipTokens moves the tokenizing position to follow the last character in the last token to which it advances. If a token is quoted, the tokenizing position (in all-default situations) follows the ending quote character.

Syntax

%currentNumber = stringTokenizer:NextPosition stringTokenizer:NextPosition = newNumber

Syntax terms

%currentNumber A numeric variable to contain the value of the current tokenizing position.
stringTokenizer A stringTokenizer object expression.
newNumber The numeric value to assign to stringTokenizer's NextPosition property.

Usage notes

  • The CurrentTokenPosition property returns the position of the initial character in the current token. Setting NextPosition does not change CurrentTokenPosition.
  • 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