CurrentTokenPosition (StringTokenizer property): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (typo)
 
Line 4: Line 4:
the current token.
the current token.


If you change the current token (by invoking <var>[[NextToken (StringTokenizer function)|NextToken]]</var>, <var>[[FindToken (StringTokenizer function)|FindToken]]</var>, or <var>[[SkipTokens (StringTokenizer function)|SkipTokens]]</var>),
If you change the current token (by invoking <var>[[NextToken (StringTokenizer function)|NextToken]]</var>, <var>[[FindToken (StringTokenizer function)|FindToken]]</var>, or <var>[[SkipTokens (StringTokenizer subroutine)|SkipTokens]]</var>),
<var>CurrentTokenPosition</var> is updated with a new value.
<var>CurrentTokenPosition</var> is updated with a new value.
If you explicitly set <var>CurrentTokenPosition</var>, the value returned by
If you explicitly set <var>CurrentTokenPosition</var>, the value returned by

Latest revision as of 19:31, 23 September 2014

Position of first character in the current token (StringTokenizer class)


This readWrite property returns or sets the position of the first character in the current token.

If you change the current token (by invoking NextToken, FindToken, or SkipTokens), CurrentTokenPosition is updated with a new value. If you explicitly set CurrentTokenPosition, the value returned by CurrentToken is adjusted accordingly.

Syntax

%currentNumber = stringTokenizer:CurrentTokenPosition stringTokenizer:CurrentTokenPosition = newNumber

Syntax terms

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

Usage notes

  • Issuing CurrentTokenPosition for a new StringTokenizer object is invalid and cancels the request until a NextToken or FindToken call establishes an initial token.
  • The NextPosition property returns the position of the character from which the tokenizer starts parsing for the next token.

    The NextPosition and CurrentTokenPosition values value are entirely independent of each other. Both properties can be set to arbitrary locations in the tokenization string. However, if these properties are never explicitly set, NextPosition will always be at least one greater than the position of the last character in the CurrentToken.

Examples

In the following request fragment, the string's first token is selected and immediately becomes the current token with current token position 1. The current token position is then explicitly moved, so the subsequent current token starts at that new position. The subsequent NextToken call, however, ignores the current token position and selects a token based on the position established by the previous NextToken call:

%tok = new(spaces=',') %tok:string = 'start,one,two,three,end' printText {~} is {%tok:nextToken} printText {~} is {%tok:currentToken} printText {~} is {%tok:currentTokenPosition} %tok:currentTokenPosition = 15 printText {~} is {%tok:currentTokenPosition} printText {~} is {%tok:currentToken} printText {~} is {%tok:nextToken}

The result is:

%tok:nextToken is start %tok:currentToken is start %tok:currentTokenPosition is 1 %tok:currentTokenPosition is 15 %tok:currentToken is three %tok:nextToken is one

See also