Programmer Guide/Command Reference/TOKEN: Difference between revisions

From STX Wiki
Jump to navigationJump to search
m (1 revision: Initial import)
No edit summary
 
(8 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
{{DISPLAYTITLE:{{SUBPAGENAME}}}}
==TOKEN==
{{PG_StringCommands}}
<var>var</var> := TOKEN [ [[Programmer_Guide/Command_Reference_Options/Silent|/Silent]] ] [ /D=<var>delimiter</var> ] [[Programmer_Guide/Command_Reference_Options/-|/-]] <var>index</var> <var>string</var>&hellip;


<code>var := TOKEN [ /S ] [ /D=delimiter ] /- <var>index</var> <var>string1 string2</var></code>
This command, similar to the <code>[[Programmer Guide/Command Reference/WORD|WORD]]</code> command, tokenises a string into words separated by a delimiter specified with the <code>/delimiter</code> option.


-> var = 'token' or empty if <var>index</var> is not a number or outside the range 0 .. nTokens-1
The command returns the respective token or an empty string if <var>index</var> is not a number or if it is outside the range 0&hellip;<var>nTokens</var>-1, <var>nTokens</var> indicating the number of available tokens in the <var>string</var> argument.


This command, similar to the <code>[[Programmer Guide/Command Reference/WORD|WORD]]</code> command, tokenises a string using blanks, or the specified delimiter.
When using <code>TOKEN</code>, do not forget to use the [[Programmer_Guide/Command_Reference_Options/-|<code>/-</code>]] option before the first argument (and after any other options). Without the [[Programmer_Guide/Command_Reference_Options/-|<code>/-</code>]] option, any argument starting with a slash will be mistaken for an option.
 
When using <code>TOKEN</code>, do not forget to use the "/-" option before the first argument (and after any other options). Without the "/-" option, any argument starting with a slash will be mistaken for an option.


;<var>index</var>
;<var>index</var>
:The zero-based index of the token to return (0 &le; <var>index</var> &le; <var>nWords</var>-1, <var>nWords</var> being the number tokens available in the <var>string</var> argument).


:The zero-based index of the word to return (0 <= <var>index</var> <= nWords-1).
;<var>string</var>&hellip;
 
:A string to tokenise. If you supply more than one string, they will still be considered one string, following {{STx}} rules for argument concatenation.
;<var>string1, string2</var>
 
:A string to tokenise.
 
;<var>/S</var>


;<code>[[Programmer_Guide/Command_Reference_Options/Silent|/Silent]]</code>
:If set, the function sets the return code on failure. Otherwise, it sets the return code to 0, even if the parameters are invalid.
:If set, the function sets the return code on failure. Otherwise, it sets the return code to 0, even if the parameters are invalid.


;<var>/D</var>
;<code>/Delimiter=<var>delimiter</var></code>
 
:Set the delimiter character. The default delimiter is a blank character.
:Set the delimiter using the following format:
 
:/D=delimiter
 
:E.g.:
 
:#var := token /D=, /- $#index $#wordlist
 
:The default delimiter is a blank.


Example:
== Example ==


<pre>
#str := set 'to be, or not to be, that is the question'
#str := set 'to be, or not to be, that is the question'
#var := token /D=, /- 1 $#str
#var := token /D=, /- 1 $#str
um The second comma separated value in the string "$#str" is "$#var"
um The second comma separated value in the string "$#str" is "$#var"
// will return ' or not to be'
// will return ' or not to be'
</pre>

Latest revision as of 10:27, 4 March 2016

var := TOKEN [ /Silent ] [ /D=delimiter ] /- index string

This command, similar to the WORD command, tokenises a string into words separated by a delimiter specified with the /delimiter option.

The command returns the respective token or an empty string if index is not a number or if it is outside the range 0…nTokens-1, nTokens indicating the number of available tokens in the string argument.

When using TOKEN, do not forget to use the /- option before the first argument (and after any other options). Without the /- option, any argument starting with a slash will be mistaken for an option.

index
The zero-based index of the token to return (0 ≤ indexnWords-1, nWords being the number tokens available in the string argument).
string
A string to tokenise. If you supply more than one string, they will still be considered one string, following STx rules for argument concatenation.
/Silent
If set, the function sets the return code on failure. Otherwise, it sets the return code to 0, even if the parameters are invalid.
/Delimiter=delimiter
Set the delimiter character. The default delimiter is a blank character.

Example

#str := set 'to be, or not to be, that is the question'
#var := token /D=, /- 1 $#str
um The second comma separated value in the string "$#str" is "$#var"
// will return ' or not to be'

Navigation menu

Personal tools