FindToken (StringTokenizer function): Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 1: | Line 1: | ||
{{Template:StringTokenizer:FindToken subtitle}} | {{Template:StringTokenizer:FindToken subtitle}} | ||
This callable method returns a <var>Boolean value</var> that indicates whether | This [[Notation conventions for methods#Callable functions|callable]] method returns a <var>Boolean value</var> that indicates whether | ||
it finds a specified token. | it finds a specified token. | ||
The value is <code>True</code> if the token is found; | The value is <code>True</code> if the token is found; |
Revision as of 00:25, 1 November 2012
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.
Not up to date - do other pages have similar error[??]: 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
%boolean | An enumeration object of type Boolean to contain the returned value of FindToken. For more information about Boolean enumerations, see "Using Boolean Enumerations". |
---|---|
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: Using the PrintText statement is described in "Targeted Text statements". Printing an enumeration value is described in ToString property "Usage notes".