mIRC Scripting
mIRC: Token Identifiers
Tokens are strings separated by a unique ASCII character known as a delimiter.
A Delimiter is an ASCII character [or group of characters] that separates two or more pieces of data (tokens)
(Please Note: in mIRC it can only be a single Chr)
ASCII is a character coding scheme used by most computers to display letters, digits and special characters. (For full list, click here) An easy way to find the ascii value of a chr is to use the $asc() ident. Example ASCII value of ! is 33 = $asc(!).
The identifiers and commands below can be used to manipulate strings in all kind of different ways:
Identifiers & Commands:
| $addtok | $deltok | $findtok | $gettok |
| $instok | $istok | $matchtok | $numtok |
| $puttok | $remtok | $reptok | $sorttok |
| $wildtok | /tokenize |
Identifiers
In the examples below, We will be using the ASCII value of a space 32, and the ASCII value of a dot 46.
$addtok
The addtok identifier adds a token to the end of the string using a given ASCII value. Duplicate tokens are ignored.
Syntax:
;Case-Sensitive version
$addtokcs(string,token,delimiter)
Example:
;will return A B C D E
echo -a $addtok(A B C D E,E,32)
;will return A B C D E, multiple tokens are not added
$deltok
The deltok identifier deletes the Nth (to an optional N2) token from a given string.
Syntax:
Example:
echo -a $deltok(%string,4,32)
;The fourth token will be removed, in this case its “nice,”.
echo -a $deltok(The.Last.Word.Is.Going.To.Be.Deleted,-1,46)
;The negative number in the token number parameter lets you go backward. So -1 will actually be the first token from the right.
$findtok
The findtok identifier can be used to find the Nth token in a string. Substituting 0 for N will return the total number of matches.
Syntax:
;Case-Sensitive version
$findtok(string,token,N,delimiter)
Example:
Var %string This is an example. This is another line.
echo -a $findtok(%string,this,0,32)
;echos 2 because the word "This" appears twice in the text.
echo -a $findtok(%string,this,2,32)
/*
echos 5 because the 2nd match to "This"
is the 5th token (seperated by space)
*/
}
$gettok
This ident simply returns the Nth token from a string.
Syntax:
Example:
var %string This is an example. mIRC is cool.
echo -a $gettok(%string,5-7,32)
;Simply returns "mIRC is cool. " - 5th to the 7th token
echo -a $gettok(%string,-3,32)
;Simply returns "mIRC" since its the 3rd token from the right
echo -a $gettok(%string,4,32)
;echos example, 4th token
}
$instok
Instok identifier, similar to $addtok, lets you add a token to a string as well as in a given position. Unlike $addtok, it will add the token even if it already exists.
Syntax:
Example:
;Will simply insert the token at the end.
echo -a $instok(A C D E,B,2,32)
;A B C D E
$istok
The istok identifier is a boolean expression that returns $true of $false depending on whether or not the token exists in the text.
Syntax:
;Case-Sensitive version
$istokcs(string,token,delimiter)
Example:
;will return $true
echo -a $istok(Red Green Blue,Yellow,32)
;will return $false
$matchtok
The matchtok identifier matches tokens that contain text. Substituting 0 for N will return the total number of matches.
Syntax:
;Case-Sensitive version
$matchtokcs(tokens,string,N,delimiter)
Example:
;will return 3, only ¾ tokens contained “n” in them
echo -a $matchtok(Apple Banana Orange Lemon,n,1,32)
;will return Banana, the first word with ‘n’ in it
$numtok
The numtok identifier is used to count the number of tokens in a string.
Syntax:
Example:
;will return 6
echo -a $numtok(Hello@Here!,$asc(@))
;will return 2
$puttok
The puttok identifier replaces the Nth token with a new one. If the Nth token does not exist, no action will take place.
Syntax:
Example:
;will return Good Night
echo -a $puttok(Testing,1 2 3,99,32)
;will return Testing, Since token 99 does not exist
$remtok
The remtok identifier removes the Nth matching token from the string. Substituting 0 for N will remove all matching tokens.
Syntax:
;Case-Sensitive version
$remtokcs(string,token,N,delimiter)
Example:
;will return This will get removed
echo -a $remtok(This is a test and this will be remove,this,0,32)
;will return is a test and will be remove
$reptok
The reptok identifier is used to replace the Nth matching token in text with a new one. Substituting 0 for N will replace all matching tokens accordingly.
Syntax:
;Case-Sensitive version
$reptokcs(string,token,NewToken,N,delimiter)
Example:
;will return @ B C D E @ B C D E @ B
echo -a $reptok(A A A,A,@,32)
;will return @ A A, The Nth parameter is not required.
$sorttok
The sorttok sorts the tokens accordingly. Sorting goes as follow: n – numeric, r – reverse, a – alphabetic, and c mode prefix.
Syntax:
;Case-Sensitive version
$sorttokcs(string,delimiter,ncra)
Example:
;will return @aa @b @hello @test %t +a
echo -a $sorttok(4 1 7 2 3 9 3,32,n)
;will return 1 2 3 3 4 7 9
$wildtok
The wildtok returns the Nth wild matching token in a string. Substituting 0 for N will return the total number of matches.
Syntax:
;Case-Sensitive version
$wildtokcs(tokens,WildMatchString,N,delimiter)
Example:
;will return #mIRC
echo -a $wildtok(a.aa.aaa.b.c,*a,0,46)
;will return 3
/tokenize
The tokenize command lets you break down the text by an ASCII delimiter. This will fill $1, $2, $3 $N each one with its own token.
Syntax:
Example:
;Will split it by spaces
echo -a $1-2 $4
;will echo the 1st through the 2nd token, as well as the 4th. Return “This is cool”

