(→Parameters) |
(→See also) |
||
(8 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | '''$gettok returns the Nth $asc(C)-delimited token from a list | + | {{mirc title|$gettok Identifier}} |
+ | '''$gettok''' returns the Nth $asc(C)-delimited token from a list. | ||
+ | |||
== Synopsis == | == Synopsis == | ||
Line 5: | Line 7: | ||
== Parameters == | == Parameters == | ||
− | '''LIST:''' Text list delimited by a character into tokens<br /> | + | '''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 {{mIRC|$asc|$asc()}} value which splits TEXT into tokens<br /> |
− | If N=0, returns total number of tokens, same as $numtok(TEXT,C)<br /> | + | If N=0, returns total number of tokens, same as {{mIRC|$numtok|$numtok(TEXT,C)}} <br /> |
− | If N is greater than the total number of tokens, returns $ | + | If N is greater than the total number of tokens, returns {{mIRC|$null|$null}} <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 delimiters.<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 delimiters.<br /> | ||
+ | '''Note:''' You can reverse the order of the number: $gettok(a b c,3-2,32) is the same as $gettok(a b c,2-3,32)<br /> | ||
+ | '''Note:''' N2 can also be negative: $gettok(a b c d e f,-2-3,32) return the token from the 3rd token to the -2th but $gettok(a b c d e f,-2--3,32) return e f, from -3 to -2<br /> | ||
+ | '''Note:''' For readability you can also code this as '''$gettok(a-b-c-d-e,2,$asc(-))'''. | ||
== Properties == | == Properties == | ||
− | |||
None | None | ||
Line 41: | Line 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( | + | <pre>//echo -a $gettok(11x22x33x44,3,120) |
− | ; returns | + | ; returns 33 because $chr(120) is lower-case x |
− | //echo -a $gettok( | + | //echo -a $gettok(x11xxxx22x33x44x,3,120) |
− | ; also returns | + | ; also returns 33 because duplicate, leading, and trailing delimiters are stripped before $gettok processes the TEXT |
− | //echo -a $gettok( | + | //echo -a $gettok(11x22X33x44,3,120) |
− | ; returns | + | ; returns 44 because the C token is case-sensitive, so capital X isn't a delimiter</pre> |
$gettok allows the range numbers to be negative | $gettok allows the range numbers to be negative | ||
Line 64: | Line 69: | ||
</pre> | </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 {{mIRC|$replace|$replace}} to change the comma in the filename into another character that cannot appear in the filename before adding as a token, then use {{mIRC|$replace|$replace}} on the extracted token to restore any comma(s). Alternatively use a character other than a comma (like '|') as a delimiter instead. |
== Compatibility == | == Compatibility == | ||
Line 70: | Line 75: | ||
== See also == | == See also == | ||
− | * {{mIRC|$ | + | {{collist |
+ | |count = 6 | ||
+ | |style = width: 100%; display: inherit; | ||
+ | | | ||
+ | * {{mIRC|$addtok}} | ||
+ | * {{mIRC|$deltok}} | ||
* {{mIRC|$findtok}} | * {{mIRC|$findtok}} | ||
+ | * {{mIRC|$instok}} | ||
+ | * {{mIRC|$istok}} | ||
* {{mIRC|$matchtok}} | * {{mIRC|$matchtok}} | ||
− | * {{mIRC|$ | + | * {{mIRC|$numtok}} |
− | |||
− | |||
− | |||
* {{mIRC|$puttok}} | * {{mIRC|$puttok}} | ||
− | |||
* {{mIRC|$remtok}} | * {{mIRC|$remtok}} | ||
* {{mIRC|$reptok}} | * {{mIRC|$reptok}} | ||
* {{mIRC|$sorttok}} | * {{mIRC|$sorttok}} | ||
− | * [[List of identifiers - mIRC]] | + | * {{mIRC|$wildtok}} |
+ | }} | ||
+ | [[List of identifiers - mIRC|Full list of identifiers]] | ||
{{mIRC identifier list}} | {{mIRC identifier list}} | ||
+ | [[Category:mIRC identifiers|gettok]] |
Latest revision as of 06:37, 30 October 2017
$gettok returns the Nth $asc(C)-delimited token from a list.
Synopsis[edit]
$gettok(<LIST>,<N>,<C>)
Parameters[edit]
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 $null
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.
Note: You can reverse the order of the number: $gettok(a b c,3-2,32) is the same as $gettok(a b c,2-3,32)
Note: N2 can also be negative: $gettok(a b c d e f,-2-3,32) return the token from the 3rd token to the -2th but $gettok(a b c d e f,-2--3,32) return e f, from -3 to -2
Note: For readability you can also code this as $gettok(a-b-c-d-e,2,$asc(-)).
Properties[edit]
None
Examples[edit]
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(11x22x33x44,3,120) ; returns 33 because $chr(120) is lower-case x //echo -a $gettok(x11xxxx22x33x44x,3,120) ; also returns 33 because duplicate, leading, and trailing delimiters are stripped before $gettok processes the TEXT //echo -a $gettok(11x22X33x44,3,120) ; returns 44 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). Alternatively use a character other than a comma (like '|') as a delimiter instead.
Compatibility[edit]
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.