Synopsis
$gettok(TEXT,N,C)
Returns the Nth $asc(C)-delimited token from text
Parameters
TEXT: Text delimited by a character into tokens
N: The token(s) to be returned. N can also be negative or a range
C: The $asc() value which splits TEXT into tokens
If N=0, returns total number of tokens, same as $numtok(TEXT,C)
If N is greater than the total number of tokens, returns $nul
If N is negative, returns tokens relative to the last token. -1 is the last token, -2 is next-to-last token, etc.
N- returns all tokens beginning with the Nth token. N1-N2 returns all tokens in the range of those 2 numbers, including the between tokens.
C delimiters consecutively-repeated or beginning or ending TEXT are stripped before processing.</pre>
Properties
None
Examples
Echo to the active window, the 2nd token as delimited by the $chr(45) hyphen:
//echo -a $gettok(a-b-c-d-e,2,45) ; returns b
$chr(32) is the space character. Echo the current month to the active window:
//echo -a The current month is $gettok($asctime,2,32)
$chr(58) is the colon, $chr(92) is the backslash:
//echo -a This $gettok($mircexe,-1,92) is installed on the $gettok($mircexe,1,58) drive letter in a program folder named $gettok($mircexe,-2,92) //var %i $gettok($mircexe,0,92) | echo -a $gettok($mircexe,1- $+ $calc(%i -1) ,92) is mIRC's path without the ending backslash
//echo -a $gettok(Sun.Mon.Tue.Wed.Thu.Fri.Sat,2-4,46) ;returns Mon.Tue.Wed (including the delimiter period between the returned tokens //echo -a $gettok(Sun.Mon.Tue.Wed.Thu.Fri.Sat,3-,46) ; returns all tokens beginning with the 3rd: Tue.Wed.Thu.Fri.Sat
//echo -a $gettok(1x2x3x4,3,120) ;returns 3 because $chr(120) is lower-case x //echo -a $gettok(x1xxxx2x3x4x,3,120) ; also returns 3 because duplicate, leading, and trailing delimiters are stripped before $gettok processes the TEXT //echo -a $gettok(1x2X3x4,3,120) ;returns 4 because the C token is case-sensitive, so capital X isn't a delimiter
Compatibility
Added: mIRC v4.7
Added on: 09 Dec 1996
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.
See also
- $numtok
- $findtok
- $matchtok
- $wildtok
- $istok
- $addtok
- $instok
- $puttok
- $deltok
- $remtok
- $reptok
- $sorttok
- List of identifiers - mIRC