|
Joined: Dec 2002
Posts: 29
Ameglian cow
|
OP
Ameglian cow
Joined: Dec 2002
Posts: 29 |
anybody can help me? i have following problems, mirc won't parse following token correctly
set %token a,b,c,,e
echo -a --> $gettok(%token,4,44) as result i get --> e <-- instead, an empty value is there a mirc bug, or just a script error from my side? any idea, guys?
Charlie
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
It's a shortcoming of the scripting langauge.
Spelling mistakes, grammatical errors, and stupid comments are intentional.
|
|
|
|
Joined: Jan 2003
Posts: 3,012
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 3,012 |
Thats the same reason why mirc doesn't allow double spaces. Any consecutive delimiters (such as spaces in a sentance) are reduced to one.
-KingTomato
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
If it is really important to handle an empty value, you could do one of two things. Store an actual space between the commas instead of nothing, or store $null if that is more suitable. Or if you have no control over the data, you can use a regular expression which is very static about its back-references. var %token = a,b,c,,e
var %re = /^(.*?),(.*?),(.*?),(.*?),(.*?)$/
var %nul = $regex(%token,%re)
echo -a $regml(1) / $regml(2) / $regml(3) / $regml(4) / $regml(5)
The only problem is you're limited to a static number of delimited items in my above example. I'm sure there's a way to make it more dynamic, but I can't think of one right now. Yet, $regml(4) indeed returns nothing. - Raccoon
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
Maybe what should be done is a property for $*tok called "all" where if you do like $gettok(.....).all it will include $null entries. That way it's still backwards compatible, but people who want this feature can use it.
|
|
|
|
Joined: Dec 2002
Posts: 29
Ameglian cow
|
OP
Ameglian cow
Joined: Dec 2002
Posts: 29 |
thanks guys for your reply all i have solved the problem with insert 0 (zero) when the value is empty.
var %token = $iif(%a,a,0) $+ , $+ $iif(%b,b,0) $+ , $+ $iif(%c,c,0) $+ , $+ $iif(%d,d,0) $+ , $+ $iif(%e,e,0)
echo -a --> $gettok(%token,4,44) i know, the code is not clean, but with this one i can fix the problems inside my script :tongue:
Charlie
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
You mean something like this? alias gettokn {
if $2 !isnum || $3 !isnum 1-255 { return }
var %c = \x $+ $base($3,10,16,2)
!.echo -q $regex(gettokn,$1,/(?<=^| $+ %c $+ )([^ $+ %c $+ ]*)(?=$| $+ %c $+ )/g)
return $regml(gettokn,$iif($2 < 0,$calc($regml(gettokn,0) + 1 + $2),$2))
} Works like $gettok(), same parameters etc. There's no support for token ranges but it does support negative indexes (e.g. $gettokn(a.b..c.d,-2,46)).
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Dec 2002
Posts: 29
Ameglian cow
|
OP
Ameglian cow
Joined: Dec 2002
Posts: 29 |
super qwerty,
this code help me so much, thanks you
Charlie
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
Qwerty... You're gonna have to share some of your mad regex skillz. / (?<=^| ... * Raccoon blinks, "Didn't know mIRC could do those..."And here I was trying to figure out how to get \G to work. Would using the /x flag save you from having to use $+ in the expression? - Raccoon
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
mIRC doesn't support any regex, PCRE does. And PCRE supports whatever Perl supports, and perl is the one that invented look behind afaik.
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
It's a matter of inherence. When I say 'mIRC could do', I'm naturally referring to mIRC and anything that it is composed of... including PCRE, C++, and x86 machine language. I never suggested Khaled was at all responsible for or supports it, or that other applications using PCRE were any less capable.
picky picky poo.
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
My point was that, 99.9% PCRE = Perl regex. And since Perl regex has lookbehind, so does PCRE, and since mIRC uses PCRE, so does mIRC.
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
Would using the /x flag save you from having to use $+ in the expression?Damn right it would... smart usage of /x, I should keep it in mind
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
|