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:

$addtok(string,token,delimiter)
;Case-Sensitive version
$addtokcs(string,token,delimiter)

Example:

echo -a $addtok(A B C D,E,32)
;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:

$addtok(string,N[-N2],delimiter)

Example:

var %string = Today is a nice, rainy day.
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:

$findtok(string,token,N,delimiter)
;Case-Sensitive version
$findtok(string,token,N,delimiter)

Example:

Alias test {
  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:

$gettok(string,N[-N2],delimiter)

Example:

Alias test {
  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:

$instok(string,token,N,delimiter)

Example:

echo -a $instok(This is an,example.,0,32)
;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:

$istok(string,token,delimiter)
;Case-Sensitive version
$istokcs(string,token,delimiter)

Example:

echo -a $istok(Red Green Blue,Blue,32)
;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:

$matchtok(tokens,string,N,delimiter)
;Case-Sensitive version
$matchtokcs(tokens,string,N,delimiter)

Example:

echo -a $matchtok(Apple Banana Orange Lemon,n,0,32)
;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:

$numtok(string,delimiter)

Example:

echo -a $numtok(one.two.three.1.2.3,46)
;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:

$puttok(string,token,N,delimiter)

Example:

echo -a $puttok(Good Morning,Night,2,32)
;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:

$remtok(string,token,N,delimiter)
;Case-Sensitive version
$remtokcs(string,token,N,delimiter)

Example:

echo -a $remtok(This text will get removed,text,1,32)
;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:

$reptok(string,token,NewToken,N,delimiter)
;Case-Sensitive version
$reptokcs(string,token,NewToken,N,delimiter)

Example:

echo -a $reptok(A B C D E A B C D E A B,A,@,0,32)
;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:

$sorttok(string,delimiter,ncra)
;Case-Sensitive version
$sorttokcs(string,delimiter,ncra)

Example:

echo -a $sorttok(+a % $+ t @b @aa @hello @test,32,c)
;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:

$wildtok(tokens,WildMatchString,token,N,delimiter)
;Case-Sensitive version
$wildtokcs(tokens,WildMatchString,N,delimiter)

Example:

echo -a $wildtok(#mIRC #IRCHelp #Network #Help,*mIRC,1,32)
;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:

/tokenize <c> <text>

Example:

tokenize 32 This is a cool 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”