Maroonbells (talk | contribs) (Create contect for empty stub page) |
Maroonbells (talk | contribs) m (Design fixes) |
||
Line 1: | Line 1: | ||
+ | '''$gettok returns the Nth $asc(C)-delimited token from a list''' | ||
+ | |||
== Synopsis == | == Synopsis == | ||
− | <pre>$gettok( | + | <pre>$gettok(<LIST>,<N>,<C>)</pre> |
− | |||
== Parameters == | == Parameters == | ||
− | ''' | + | '''LIST:''' Text list delimited by a character into tokens<br /> |
'''N:''' The token(s) to be returned. N can also be negative or a range<br /> | '''N:''' The token(s) to be returned. N can also be negative or a range<br /> | ||
'''C:''' The $asc() value which splits TEXT into tokens<br /> | '''C:''' The $asc() value which splits TEXT into tokens<br /> | ||
Line 11: | Line 12: | ||
If N is greater than the total number of tokens, returns $nul<br /> | If N is greater than the total number of tokens, returns $nul<br /> | ||
If N is negative, returns tokens relative to the last token. -1 is the last token, -2 is next-to-last token, etc.<br /> | If N is negative, returns tokens relative to the last token. -1 is the last token, -2 is next-to-last token, etc.<br /> | ||
− | N- returns all tokens beginning with the Nth token. N1-N2 returns all tokens in the range of those 2 numbers, including the between | + | N- returns all tokens beginning with the Nth token. N1-N2 returns all tokens in the range of those 2 numbers, including the between delimiters.<br /> |
C delimiters consecutively-repeated or beginning or ending TEXT are stripped before processing.</pre> | C delimiters consecutively-repeated or beginning or ending TEXT are stripped before processing.</pre> | ||
+ | |||
== Properties == | == Properties == | ||
Line 25: | Line 27: | ||
$chr(32) is the space character. Echo the current month to the active window: | $chr(32) is the space character. Echo the current month to the active window: | ||
<pre>//echo -a The current month is $gettok($asctime,2,32)</pre> | <pre>//echo -a The current month is $gettok($asctime,2,32)</pre> | ||
+ | |||
+ | This returns ''Mon Tue'' because the space between %x %y becomes the 2nd delimiter: | ||
+ | <pre>//var %x Sun Mon | var %y Tue Wed Thu Fri Sat | echo -a $gettok(%x %y,2-3,32)</pre> | ||
$chr(58) is the colon, $chr(92) is the backslash: | $chr(58) is the colon, $chr(92) is the backslash: | ||
Line 33: | Line 38: | ||
<pre>//echo -a $gettok(Sun.Mon.Tue.Wed.Thu.Fri.Sat,2-4,46) | <pre>//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 | + | ; returns Mon.Tue.Wed (including the delimiter period between the returned tokens |
//echo -a $gettok(Sun.Mon.Tue.Wed.Thu.Fri.Sat,3-,46) | //echo -a $gettok(Sun.Mon.Tue.Wed.Thu.Fri.Sat,3-,46) | ||
; returns all tokens beginning with the 3rd: Tue.Wed.Thu.Fri.Sat</pre> | ; returns all tokens beginning with the 3rd: Tue.Wed.Thu.Fri.Sat</pre> | ||
<pre>//echo -a $gettok(1x2x3x4,3,120) | <pre>//echo -a $gettok(1x2x3x4,3,120) | ||
− | ;returns 3 because $chr(120) is lower-case x | + | ; returns 3 because $chr(120) is lower-case x |
//echo -a $gettok(x1xxxx2x3x4x,3,120) | //echo -a $gettok(x1xxxx2x3x4x,3,120) | ||
; also returns 3 because duplicate, leading, and trailing delimiters are stripped before $gettok processes the TEXT | ; also returns 3 because duplicate, leading, and trailing delimiters are stripped before $gettok processes the TEXT | ||
//echo -a $gettok(1x2X3x4,3,120) | //echo -a $gettok(1x2X3x4,3,120) | ||
− | ;returns 4 because the C token is case-sensitive, so capital X isn't a delimiter</pre> | + | ; returns 4 because the C token is case-sensitive, so capital X isn't a delimiter</pre> |
+ | |||
+ | $gettok allows the range numbers to be negative | ||
+ | <pre>//echo -a $gettok(Sun.Mon.Tue.Wed.Thu.Fri.Sat,-4- $+ -2,46) | ||
+ | ; returns the 4th-from-last through 2nd-from-last tokens | ||
+ | //echo -a $gettok(Sun.Mon.Tue.Wed.Thu.Fri.Sat,-2-,46) | ||
+ | ; returns the last 2 tokens | ||
+ | //echo -a $gettok(Sun.Mon.Tue.Wed.Thu.Fri.Sat,2- $+ -2,46) | ||
+ | ; returns 2nd token through 2nd-from-last token | ||
+ | </pre> | ||
+ | |||
+ | $gettok puts range numbers in the correct order before evaluating them. | ||
+ | <pre>//echo -a $gettok(Sun.Mon.Tue.Wed.Thu.Fri.Sat,4-3,46) | ||
+ | ; returns same results as if range 3-4 were used | ||
+ | //echo -a $gettok(Sun.Mon.Tue.Wed.Thu.Fri.Sat,-4-3,46) | ||
+ | ; returns 4th-from-last token thru the 3rd token regardless whether the 3rd token is the earlier or later token in the list. | ||
+ | </pre> | ||
+ | |||
+ | '''NOTE:''' $gettok differs from CSV format in that it does not use double-quotes to allow a delimiter to be part of another token. If you want $filename to be a token in a comma-delimited list of tokens, you should use $replace to change the comma in the filename into another character that cannot appear in the filename before adding as a token, then use $replace on the extracted token to restore any comma(s). | ||
== Compatibility == | == Compatibility == |
Revision as of 10:06, 12 June 2017
$gettok returns the Nth $asc(C)-delimited token from a list
Synopsis
$gettok(<LIST>,<N>,<C>)
Parameters
LIST: Text list 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 delimiters.
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)
This returns Mon Tue because the space between %x %y becomes the 2nd delimiter:
//var %x Sun Mon | var %y Tue Wed Thu Fri Sat | echo -a $gettok(%x %y,2-3,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
$gettok allows the range numbers to be negative
//echo -a $gettok(Sun.Mon.Tue.Wed.Thu.Fri.Sat,-4- $+ -2,46) ; returns the 4th-from-last through 2nd-from-last tokens //echo -a $gettok(Sun.Mon.Tue.Wed.Thu.Fri.Sat,-2-,46) ; returns the last 2 tokens //echo -a $gettok(Sun.Mon.Tue.Wed.Thu.Fri.Sat,2- $+ -2,46) ; returns 2nd token through 2nd-from-last token
$gettok puts range numbers in the correct order before evaluating them.
//echo -a $gettok(Sun.Mon.Tue.Wed.Thu.Fri.Sat,4-3,46) ; returns same results as if range 3-4 were used //echo -a $gettok(Sun.Mon.Tue.Wed.Thu.Fri.Sat,-4-3,46) ; returns 4th-from-last token thru the 3rd token regardless whether the 3rd token is the earlier or later token in the list.
NOTE: $gettok differs from CSV format in that it does not use double-quotes to allow a delimiter to be part of another token. If you want $filename to be a token in a comma-delimited list of tokens, you should use $replace to change the comma in the filename into another character that cannot appear in the filename before adding as a token, then use $replace on the extracted token to restore any comma(s).
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