FindToken (StringTokenizer function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
 
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Template:StringTokenizer:FindToken subtitle}}
{{Template:StringTokenizer:FindToken subtitle}}


This callable method returns a Boolean value that indicates whether
This [[Notation conventions for methods#Callable functions|callable]] method returns a <var>[[Boolean enumeration]]</var> value that indicates whether
it finds a specified token.
it finds a specified token. The value is <code>True</code> if the token is found; otherwise it is <code>False</code>.
The value is <code>True</code> if the token is found;
The search starts from the tokenizing position, the value of which is returned by <var>[[NextPosition (StringTokenizer property)|NextPosition]]</var>.
otherwise it is <code>False</code>.
The search starts from the tokenizing position,
the value of which is returned by [[NextPosition (StringTokenizer property)|NextPosition]].


If the token is found, the position in
If the token is found, the position in the string is advanced past the found token, and <var>[[CurrentToken (StringTokenizer function)|CurrentToken]]</var>
the string is advanced past the found token, and [[CurrentToken (StringTokenizer function)|CurrentToken]]
will return the found token.
will return the found token.
Otherwise, [[AtEnd (StringTokenizer function)|AtEnd]] is set to <code>True</code>, and CurrentToken
Otherwise, <var>[[AtEnd (StringTokenizer function)|AtEnd]]</var> is set to <code>True</code>, and <var>CurrentToken</var>
is set to the last token at the end of the string.
is set to the last token at the end of the string.


The delimiters that are involved in determining the tokens
are set initially by the [[New (StringTokenizer constructor)|New]] constructor
that instantiates the <var>StringTokenizer</var> object.
The delimiters can be modified by the [[Spaces (StringTokenizer property)|Spaces]],
[[Quotes (StringTokenizer property)|Quotes]], and [[TokenChars (StringTokenizer property)|TokenChars]] properties.
==Syntax==
==Syntax==
{{Template:StringTokenizer:FindToken syntax}}
{{Template:StringTokenizer:FindToken syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%boolean</th>
<tr><th>%boolean</th>
<td>An enumeration object of type <var>Boolean</var> to contain the returned value of <var>FindToken</var>.
<td>An enumeration object of type <var>Boolean</var> to contain the returned value of <var>FindToken</var>.</td></tr>


For more information about <var>Boolean</var> enumerations, see [[Enumerations#Using_Boolean_enumerations|"Using Boolean Enumerations"]].</td></tr>
<tr><th>stringTokenizer</th>
<tr><th>stringTokenizer</th>
<td>A <var>StringTokenizer</var> object expression. </td></tr>
<td>A <var>StringTokenizer</var> object expression. </td></tr>
<tr><th>string</th>
<tr><th>string</th>
<td>A string that is the token to be located.</td></tr>
<td>A string that is the token to be located.</td></tr>
Line 36: Line 28:
<ul>
<ul>
<li>For a new <var>StringTokenizer</var> instance, issuing <var>FindToken</var>,
<li>For a new <var>StringTokenizer</var> instance, issuing <var>FindToken</var>,
[[NextToken (StringTokenizer function)|NextToken]], or [[SkipTokens (StringTokenizer subroutine)|SkipTokens]] is
<var>[[NextToken (StringTokenizer function)|NextToken]]</var>, or <var>[[SkipTokens (StringTokenizer subroutine)|SkipTokens]]</var> is required before <var>[[CurrentToken (StringTokenizer function)|CurrentToken]]</var> may be issued without error.
required before [[CurrentToken (StringTokenizer function)|CurrentToken]] may be issued without error.
 
<li>The NextToken and [[PeekToken (StringTokenizer function)|PeekToken]]
<li>The <var>NextToken</var> and <var>[[PeekToken (StringTokenizer function)|PeekToken]]</var>
functions also return the next token.
functions also return the next token. Like <var>FindToken</var>, <var>NextToken</var>
Like <var>FindToken</var>, NextToken
advances the tokenizing position to the character or position following that token.
advances the tokenizing position to the character or position following that token.
PeekToken, however, does not advance the tokenizing position.
<var>PeekToken</var>, however, does not advance the tokenizing position.
</ul>
</ul>
==Examples==
==Examples==
The following code fragment shows a <var>FindToken</var> call that locates its target,
The following code fragment shows a <var>FindToken</var> call that locates its target,
then a <var>FindToken</var> call that does not locate its target:
then a <var>FindToken</var> call that does not locate its target:
<p class="code">%tok = new(tokenchars='-')
<p class="code">%tok = new(tokenchars='-')
%tok:string = 'Content-Transfer-Encoding: 7bit'
%tok:string = 'Content-Transfer-Encoding: 7bit'
PrintText {~} is {%tok:findToken('Transfer')}
[[Targeted Text statements#AuditText, PrintText, and TraceText|PrintText]] {~} is {%tok:findToken('Transfer')}
PrintText {~} is {%tok:findToken('8bit')}
[[Targeted Text statements#AuditText, PrintText, and TraceText|PrintText]] {~} is {%tok:findToken('8bit')}
PrintText {~} is {%tok:AtEnd}
PrintText {~} is {%tok:AtEnd}
PrintText {~} is {%tok:currentToken}
PrintText {~} is {%tok:currentToken}
Line 62: Line 53:
%tok:currentToken is 7bit
%tok:currentToken is 7bit
</p>
</p>
'''Note:'''
<p class="note">'''Note:'''
Using the PrintText statement is described in [[Targeted Text statements|PrintText]].
Printing an enumeration value is described in the <var>ToString</var> property discussion in [[Enumerations#printenum|Usage notes on the "Enumerations" page]]. </p>
Using PrintText to print an enumeration value is described in the first "Note" ??
 
in [[Enumerations#Using enumerations|Using enumerations]].
==See also==
==See also==
{{Template:StringTokenizer:FindToken footer}}
{{Template:StringTokenizer:FindToken footer}}

Latest revision as of 23:19, 10 October 2014

Search for specified token (StringTokenizer class)


This callable method returns a Boolean enumeration value that indicates whether it finds a specified token. The value is True if the token is found; otherwise it is False. The search starts from the tokenizing position, the value of which is returned by NextPosition.

If the token is found, the position in the string is advanced past the found token, and CurrentToken will return the found token. Otherwise, AtEnd is set to True, and CurrentToken is set to the last token at the end of the string.

Syntax

[%boolean =] stringTokenizer:FindToken( string) Throws MismatchedQuote

Syntax terms

%boolean An enumeration object of type Boolean to contain the returned value of FindToken.
stringTokenizer A StringTokenizer object expression.
string A string that is the token to be located.

Usage notes

  • For a new StringTokenizer instance, issuing FindToken, NextToken, or SkipTokens is required before CurrentToken may be issued without error.
  • The NextToken and PeekToken functions also return the next token. Like FindToken, NextToken advances the tokenizing position to the character or position following that token. PeekToken, however, does not advance the tokenizing position.

Examples

The following code fragment shows a FindToken call that locates its target, then a FindToken call that does not locate its target:

%tok = new(tokenchars='-') %tok:string = 'Content-Transfer-Encoding: 7bit' PrintText {~} is {%tok:findToken('Transfer')} PrintText {~} is {%tok:findToken('8bit')} PrintText {~} is {%tok:AtEnd} PrintText {~} is {%tok:currentToken}

The result is:

%tok:findToken('Transfer') is True %tok:findToken('8bit') is False %tok:AtEnd is True %tok:currentToken is 7bit

Note: Printing an enumeration value is described in the ToString property discussion in Usage notes on the "Enumerations" page.

See also