CurrentToken (StringTokenizer function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
 
(2 intermediate revisions by 2 users not shown)
Line 3: Line 3:
This method returns the string value of the current token.
This method returns the string value of the current token.
The current token is typically the most recent token
The current token is typically the most recent token
returned by [[NextToken (StringTokenizer function)|NextToken]] or [[FindToken (StringTokenizer function)|FindToken]].
returned by <var>[[NextToken (StringTokenizer function)|NextToken]]</var> or <var>[[FindToken (StringTokenizer function)|FindToken]]</var>.
<var>CurrentToken</var> is invalid and cancels the request until one of
<var>CurrentToken</var> is invalid and cancels the request until one of these calls has been made.
these calls has been made.
 
As described in [[#Usage notes|"Usage Notes"]], below, you can also update the current
token by explicitly setting the value of <var>[[CurrentTokenPosition (StringTokenizer property)|CurrentTokenPosition]]</var>.


As described in "Usage Notes," below, you can also update the current
token by explicitly setting the value of [[CurrentTokenPosition (StringTokenizer property)|CurrentTokenPosition]].
==Syntax==
==Syntax==
{{Template:StringTokenizer:CurrentToken syntax}}
{{Template:StringTokenizer:CurrentToken syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%string</th>
<tr><th>%string</th>
<td>A string variable to receive the value of the current token. </td></tr>
<td>A string variable to receive the value of the current token. </td></tr>
<tr><th>stringTokenizer</th>
<tr><th>stringTokenizer</th>
<td>A <var>StringTokenizer</var> object variable.</td></tr>
<td>A <var>StringTokenizer</var> object variable.</td></tr>
Line 21: Line 23:
==Usage notes==
==Usage notes==
<ul>
<ul>
<li>The [[CurrentTokenPosition (StringTokenizer property)|CurrentTokenPosition]] property is the position of
<li>The <var>CurrentTokenPosition</var> property is the position of the initial character in the current token.
the initial character in the current token.
Conversely, the current token always starts at the position given by
Conversely, the current token always starts at the position given by
<var>CurrentTokenPosition</var>.
<var>CurrentTokenPosition</var>.
If you reset <var>CurrentTokenPosition</var>, you automatically modify the current token
If you reset <var>CurrentTokenPosition</var>, you automatically modify the current token
substring &mdash; but this has no effect on a subsequent <var>NextToken</var>
substring &mdash; but this has no effect on a subsequent <var>NextToken</var>
or [[NextPosition (StringTokenizer property)|NextPosition]] call.
or <var>[[NextPosition (StringTokenizer property)|NextPosition]]</var> call.
</ul>
</ul>
==Examples==
==Examples==
The following request fragment shows how the successful execution
The following request fragment shows how the successful execution
of <var>NextToken</var> advances the current token and current token position.
of <var>NextToken</var> advances the current token and current token position.
For an example where the <var>CurrentToken</var> value follows an explicit
For an example where the <var>CurrentToken</var> value follows an explicit
setting of <var>CurrentTokenPosition</var>, see [[??]] refid=tkxmpcp..
setting of <var>CurrentTokenPosition</var>, see that method's [[CurrentTokenPosition (StringTokenizer property)#Examples|Examples]] section.
<p class="code">%tok = new
<p class="code">%tok = new
%tok:string = 'current token example'
%tok:string = 'current token example'
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 61: Line 62:
%tok:currentTokenPosition is 15
%tok:currentTokenPosition is 15
</p>
</p>
==See also==
==See also==
{{Template:StringTokenizer:CurrentToken footer}}
{{Template:StringTokenizer:CurrentToken footer}}

Latest revision as of 17:46, 10 October 2014

String value of current token (StringTokenizer class)


This method returns the string value of the current token. The current token is typically the most recent token returned by NextToken or FindToken. CurrentToken is invalid and cancels the request until one of these calls has been made.

As described in "Usage Notes", below, you can also update the current token by explicitly setting the value of CurrentTokenPosition.

Syntax

%string = stringTokenizer:CurrentToken Throws MismatchedQuote, OutOfBounds

Syntax terms

%string A string variable to receive the value of the current token.
stringTokenizer A StringTokenizer object variable.

Usage notes

  • The CurrentTokenPosition property is the position of the initial character in the current token. Conversely, the current token always starts at the position given by CurrentTokenPosition. If you reset CurrentTokenPosition, you automatically modify the current token substring — but this has no effect on a subsequent NextToken or NextPosition call.

Examples

The following request fragment shows how the successful execution of NextToken advances the current token and current token position. For an example where the CurrentToken value follows an explicit setting of CurrentTokenPosition, see that method's Examples section.

%tok = new %tok:string = 'current token example' PrintText {~} is {%tok:nextToken} PrintText {~} is {%tok:currentToken} PrintText {~} is {%tok:currentTokenPosition} PrintText {~} is {%tok:nextToken} PrintText {~} is {%tok:currentTokenPosition} PrintText {~} is {%tok:currentToken} PrintText {~} is {%tok:nextToken} PrintText {~} is {%tok:currentToken} PrintText {~} is {%tok:currentTokenPosition}

The result is:

%tok:nextToken is current %tok:currentToken is current %tok:currentTokenPosition is 1 %tok:nextToken is token %tok:currentTokenPosition is 9 %tok:currentToken is token %tok:nextToken is example %tok:currentToken is example %tok:currentTokenPosition is 15

See also