Yw,
regarding /tokenize, its pretty easy and very helpful once you get the hang of it.
As you know in a string, you have tokens seperated from each other by a delimiter.
1. Basic token/delimiter explanation String:
this is a test |
delimiter = a space or $chr(
32)
String:
this,is,a,test |
delimiter = a comma or $chr(
44)
Since you are already used to using $gettok and other token identifiers this is not new to you.
2. Tokenizing a string /tokenize 44 this,is,a,test The tokenize command searched for tokens seperated by commas, and stored them in the identifiers $1, $2, ....$N
$0 -> total amount of tokens:
4 $1 -> first token:
this $2 -> second token:
is $3 -> third token:
a $4 -> fourth token:
test $1- ->
this is a test As you see, tokenizing a string based on a certain delimiter (comma in our example), the tokens are "saved" in parameters $N which can be easily retrieved. As shown, the delimiters are gone in the tokenized string!
var %string = this,is,a,test
$gettok(%string,0,44) is the same as $0
$gettok(%string,1,44) is the same as $1
$gettok(%string,2-4,44) is the same as $2-4
...
3. Consequences of tokenizing a string A] When tokenizing a string for a specific delimiter, mIRC will analyse the string, and will fill the $N parameters with the tokens seperated by the chosen delimiter.
Attention, one $N identifier can contain multiple words as shown in this example: /tokenize 44 this, is a test Mirc sees that there are 2 tokens (that's right, 2 tokens, not 4) seperated by a comma.
$1 -->
this $2 -->
_is a test (the
_ is a space in this example)
$0 -->
2 B]
Very important! When tokenizing a string, the $N parameters are filled as stated earlier, though this means that the previous contents of those $N identifiers are removed! So if you know you're going to tokenize, then you're best off, with putting the original $1- in a variable.
To explain what I mean here's an example:
/test1 auto identify
[color:red] [/color]
alias test1 {
[color:red] [/color]
; input string passed to the alias : "auto identify" stored in %input
var %input = $1-
[color:red] [/color]
tokenize 44 $readini(perform.ini,perform,command)
[color:red] [/color]
; due to the tokenizing, the original values $1 = auto, and $2 = identify, are now
; overwritten with the values that were returned by the $readini
[color:red] [/color]
...
}
4. Sexy usage of /tokenize A]
There is this really nifty identifier
$* that can be used along with /tokenize like this:
//tokenize 32 one two three four five | echo -a $*
This will show the following on your screen:
one
two
three
four
five
In other words, the $* identifier puts each delimited token on a new line.
B]
Here's an example of how to get the value of $N in a loop:
alias test2 {
tokenize 46 1.2.3.4.5.6.7.8.9.10
var %x = $0
while (%x) { echo -a $($+($,%x),2) | dec %x }
}
This will echo on each line the value of $N identifier, so $10, then $9, $8, ...
However, if you payed attention, then you could just have achieved the same thing by doing:
alias test3 {
tokenize 46 $sorttok(1.2.3.4.5.6.7.8.9.10,46,rn)
echo -a $*
}
Anyway, there might still be a couple of things to mention about /tokenize but this pretty much covers it. Hope you now fully understand the functionality of /tokenize
Greets