FindToken (StringTokenizer function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 16: Line 16:
The delimiters that are involved in determining the tokens
The delimiters that are involved in determining the tokens
are set initially by the [[New (StringTokenizer constructor)|New]] constructor
are set initially by the [[New (StringTokenizer constructor)|New]] constructor
that instantiates the StringTokenizer object.
that instantiates the <var>StringTokenizer</var> object.
The delimiters can be modified by the [[Spaces (StringTokenizer property)|Spaces]],
The delimiters can be modified by the [[Spaces (StringTokenizer property)|Spaces]],
[[Quotes (StringTokenizer property)|Quotes]], and [[TokenChars (StringTokenizer property)|TokenChars]] properties.
[[Quotes (StringTokenizer property)|Quotes]], and [[TokenChars (StringTokenizer property)|TokenChars]] properties.
Line 24: Line 24:
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%bool</th>
<tr><th>%bool</th>
<td>An enumeration object of type Boolean to contain the returned value of FindToken.
<td>An enumeration object of type Boolean to contain the returned value of <var>FindToken</var>.
  For more information about Boolean enumerations, see [[Using Boolean enumerations]]. </td></tr>
  For more information about Boolean enumerations, see [[Using Boolean enumerations]]. </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>
<tr><th>string</th>
<tr><th>string</th>
<td>A string or string variable that is the token to be located.</td></tr>
<td>A string or string variable that is the token to be located.</td></tr>
Line 33: Line 33:
==Usage notes==
==Usage notes==
<ul>
<ul>
<li>For a new StringTokenizer instance, issuing FindToken,
<li>For a new <var>StringTokenizer</var> instance, issuing <var>FindToken</var>,
[[NextToken (StringTokenizer function)|NextToken]], or [[SkipTokens (StringTokenizer subroutine)|SkipTokens]] is
[[NextToken (StringTokenizer function)|NextToken]], or [[SkipTokens (StringTokenizer subroutine)|SkipTokens]] is
required before [[CurrentToken (StringTokenizer function)|CurrentToken]] 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 NextToken and [[PeekToken (StringTokenizer function)|PeekToken]]
functions also return the next token.
functions also return the next token.
Like FindToken, NextToken
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.
PeekToken, however, does not advance the tokenizing position.
Line 44: Line 44:
==Examples==
==Examples==


The following code fragment shows a FindToken call that locates its target,
The following code fragment shows a <var>FindToken</var> call that locates its target,
then a FindToken call that does not locate its target:
then a <var>FindToken</var> call that does not locate its target:
<pre>
<pre>
     %tok = new(tokenchars='-')
     %tok = new(tokenchars='-')

Revision as of 21:47, 6 February 2011

Search for specified token (StringTokenizer class)


This callable method returns a Boolean 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.

The delimiters that are involved in determining the tokens are set initially by the New constructor that instantiates the StringTokenizer object. The delimiters can be modified by the Spaces, Quotes, and TokenChars properties.

Syntax

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

Syntax terms

%bool An enumeration object of type Boolean to contain the returned value of FindToken. For more information about Boolean enumerations, see Using Boolean enumerations.
%tok A StringTokenizer object variable.
string A string or string variable 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: Using the PrintText statement is described in PrintText. Using PrintText to print an enumeration value is described in the first "Note" ?? in Using enumerations.

See also