NextPosition (StringTokenizer property): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 10: Line 10:
[[FindToken (StringTokenizer function)|FindToken]], or [[NextChar (StringTokenizer function)|NextChar]].
[[FindToken (StringTokenizer function)|FindToken]], or [[NextChar (StringTokenizer function)|NextChar]].


Well, not exactly. For example, SkipTokens affects it, and if token is quoted (& all else defaults), it's position after quote.
Well, not exactly. [[??]] For example, SkipTokens affects it, and if token is quoted (& all else defaults), it's position after quote.
==Syntax==
==Syntax==
{{Template:StringTokenizer:NextPosition syntax}}
{{Template:StringTokenizer:NextPosition syntax}}

Revision as of 20:26, 23 May 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. Its initial value is 1. 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.

Well, not exactly. ?? For example, SkipTokens affects it, and if token is quoted (& all else defaults), it's position after quote.

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 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