$TOKEN (get token)
$TOKEN extracts a token from a specified character string as defined by the position of the token to be extracted and a separator character.
Syntax
return-value=$TOKEN(base-character-string,extraction-token-position,separator-character)
Values
-
return-value
Specifies the name of the variable into which the extracted token is set.
-
base-character-string
Specifies the character string from which the token is extracted, either as a constant or a variable. A constant must be enclosed in single quotation marks ('').
-
extraction-token-position
Specifies the position of the token to be extracted, either as a constant or a variable. A constant must be enclosed in single quotation marks (''). Specify the sequential number of the token to be extracted, assuming that the first token indicated by the separator character is 0. For example, with respect to the character string aaa,bbb,ccc,ddd, the characters extracted (aaa) as delimited by the separator character become the token. In this example, 0 to 3 correspond to the positions of the following token.
0: aaa
1: bbb
2: ccc
3: ddd
If an invalid token position or an out-of-range extraction is specified, a 0-byte character string is returned.
-
separator-character
Specifies the character to be used to separate tokens, either as a constant or a variable. Usable characters are alphanumeric characters and symbols. A constant must be enclosed in single quotation marks ('').
Status
The following table lists and describes the possible statuses:
Status |
Description |
---|---|
NORMAL |
Normal end |
NODATA |
The value specified by base-character-string was not found at the position specified by extraction-token-position. |
ERROR |
— |
Script execution interrupted |
An invalid argument was specified, or an error other than the above occurred. |
- Legend:
-
—: Not applicable
Example
The following example sets the character string ABC/DEF/GHI into NAME, and then extracts DEF from NAME and sets it into VALUE:
[SET_VALUE] DATA = 'ABC/DEF/GHI' VAL = $TOKEN(DATA,1,'/') MSG = 'TOKEN = ' + VAL $ECHO(MSG)
- Execution result:
-
TOKEN = DEF