I wrote a function a long time ago (~v5.51) that I called $isswitch. It's very messy but did the job... yet, I'd like to see it built into mIRC, considering that mIRC already does this internally for every command with switch parameters.
$isflag(%string, [N/-flag], [N], [+-/])
Returns the Nth flag (aka switch) in a string if a number is specified. If N is 0, then the number of flags is returned. If a flag is specified, it returns a number of occurances of that flag in the string. The optional third parameter allows you to specify which flag you're refering to, if it appears more than once. The optional fourth parameter allows you to specify what symbols identify a flag's polarity.
Properties: val, pos, pol, flag.
val returns the value associated with that flag, if it has one.
pos returns the flag's relative position.
pol returns the flag's polarity, that is, the switch character used. (+-/)
flag returns the full flag, including its polarity character and value.
Examples:
simple_use {
if ($isflag($1)) {
if ($isflag($1,-x) do this
if ($isflag($1,+y) do that
if ($isflag($1,z) move zig
tokenize 32 $2-
}
do stuff $1-
}
advanced_use {
var %i = 0, %n = $isflag($1,0)
WHILE (%i < %n) {
inc %i
echo -a Flag %i : $isflag($1,%i).flag
if ( $isflag($1,%i).pol == + ) mode $chan - $+ $isflag($1,%i)
} }
Better Examples:
$isflag(-ti2m) == 3 (total flags)
$isflag(-ti2m,0) == 3 (total flags)
$isflag(-ti2m,-i) == 1 (total occurances)
$isflag(-ti2m,i).val == 2 (value of flag)
$isflag(-ti2m,i,1).val == 2 (value of 1st i flag)
$isflag(-ti2m,2) == i (Nth flag)
$isflag(-ti2m,i).pos == 2 (position of flag, not counting polarity character or values)
$isflag(-ti2m,i).pol == - (polarity of this flag)
$isflag(-ti2m,i).flag == -i2 (the complete flag, including polarity and value)
$isflag(+a-b/c2@d&f5*g, 3, @*-+&/) == c (you get the idea)
- Raccoon