CurrentTokenPosition (StringTokenizer property): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 5: Line 5:


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


Line 16: Line 16:
<td>A numeric variable to set or contain the returned value of the current token's first character. </td></tr>
<td>A numeric variable to set or contain the returned value of the current token's first character. </td></tr>
<tr><th>%tok</th>
<tr><th>%tok</th>
<td>A StringTokenizer object variable.</td></tr>
<td>A <var>StringTokenizer</var> object variable.</td></tr>
</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<ul>
<li>Issuing CurrentTokenPosition for a new StringTokenizer object is invalid
<li>Issuing <var>CurrentTokenPosition</var> for a new <var>StringTokenizer</var> object is invalid
and cancels the request until
and cancels the request until
a [[NextToken (StringTokenizer function)|NextToken]] or [[FindToken (StringTokenizer function)|FindToken]]
a [[NextToken (StringTokenizer function)|NextToken]] or [[FindToken (StringTokenizer function)|FindToken]]
Line 29: Line 29:
token after the most recent call of NextToken).
token after the most recent call of NextToken).


The NextPosition value is entirely independent from the CurrentTokenPosition value,
The NextPosition value is entirely independent from the <var>CurrentTokenPosition</var> value,
and vice versa.
and vice versa.
Both properties can be set to arbitrary locations in the tokenization string.
Both properties can be set to arbitrary locations in the tokenization string.

Revision as of 21:47, 6 February 2011

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

%pos A numeric variable to set or contain the returned value of the current token's first character.
%tok A StringTokenizer object variable.

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 (often this is the position that follows the last character in the current token after the most recent call of NextToken). 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. However, if these properties are never explicitly set, they will always have the relationship stated in the previous paragraph.

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