CurrentTokenPosition (StringTokenizer property): Difference between revisions
m (1 revision) |
m (typo) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{Template:StringTokenizer:CurrentTokenPosition subtitle}} | {{Template:StringTokenizer:CurrentTokenPosition subtitle}} | ||
This readWrite property returns or sets the position of the first character in | This [[Classes and Objects#readWrite|readWrite]] property returns or sets the position of the first character in | ||
the current token. | the current token. | ||
If you change the current token (by invoking <var>NextToken</var>, <var>FindToken</var>, or <var>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 | ||
[[CurrentToken (StringTokenizer function)|CurrentToken]] is adjusted accordingly. | <var>[[CurrentToken (StringTokenizer function)|CurrentToken]]</var> is adjusted accordingly. | ||
==Syntax== | ==Syntax== | ||
{{Template:StringTokenizer:CurrentTokenPosition syntax}} | {{Template:StringTokenizer:CurrentTokenPosition syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>% | <tr><th>%currentNumber</th> | ||
<td>A numeric variable to | <td>A numeric variable to contain the value of the current token's position.</td></tr> | ||
<tr><th> | |||
<td>A <var> | <tr><th>stringTokenizer</th> | ||
<td>A <var>stringTokenizer</var> object expression.</td></tr> | |||
<tr><th>newNumber</th> | |||
<td>The numeric value to assign to <var class="term">stringTokenizer</var>'s <var>CurrentTokenPosition</var> property.</td></tr> | |||
</table> | </table> | ||
Line 25: | Line 30: | ||
a <var>[[NextToken (StringTokenizer function)|NextToken]]</var> or <var>[[FindToken (StringTokenizer function)|FindToken]]</var> | a <var>[[NextToken (StringTokenizer function)|NextToken]]</var> or <var>[[FindToken (StringTokenizer function)|FindToken]]</var> | ||
call establishes an initial token. | call establishes an initial token. | ||
<li>The <var>[[NextPosition (StringTokenizer property)|NextPosition]]</var> property returns the position of | <li>The <var>[[NextPosition (StringTokenizer property)|NextPosition]]</var> property returns the position of | ||
the character from which the tokenizer starts parsing for the next token. | the character from which the tokenizer starts parsing for the next token. | ||
< | <p> | ||
The <var>NextPosition</var> and <var>CurrentTokenPosition</var> values value are entirely independent of each other. | The <var>NextPosition</var> and <var>CurrentTokenPosition</var> values value are entirely independent of each other. | ||
Both properties can be set to arbitrary locations in the tokenization string. | Both properties can be set to arbitrary locations in the tokenization string. | ||
However, if these properties are never explicitly set, <var>NextPosition</var> will always be at least one greater than the position of the last character in the <var>CurrentToken</var>. | However, if these properties are never explicitly set, <var>NextPosition</var> will always be at least one greater than the position of the last character in the <var>CurrentToken</var>.</p> | ||
</ul> | </ul> | ||
Line 43: | Line 49: | ||
<p class="code">%tok = new(spaces=',') | <p class="code">%tok = new(spaces=',') | ||
%tok:string = 'start,one,two,three,end' | %tok:string = 'start,one,two,three,end' | ||
printText {~} is {%tok:nextToken} | [[Targeted Text statements#AuditText, PrintText, and TraceText|printText]] {~} is {%tok:nextToken} | ||
printText {~} is {%tok:currentToken} | printText {~} is {%tok:currentToken} | ||
printText {~} is {%tok:currentTokenPosition} | printText {~} is {%tok:currentTokenPosition} | ||
Line 60: | Line 66: | ||
%tok:nextToken is one | %tok:nextToken is one | ||
</p> | </p> | ||
==See also== | ==See also== | ||
{{Template:StringTokenizer:CurrentTokenPosition footer}} | {{Template:StringTokenizer:CurrentTokenPosition footer}} |
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