mIRC Home    About    Download    Register    News    Help

Print Thread
#163850 05/11/06 06:07 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
According to the help file
Code:
 $gettok(a.b.c.d.e,2-,46) 
returns b.c.d.e (and it does)
And to my understanding $gettok(a.b.c.d.e,2--1,46) should return b.c.d
But it doesn't (or at least not in 6.2)
When I try it, all I get is b (equivalent of $gettok(a.b.c.d.e,2,46)

Is this a bug, or a misunderstanding?

#163851 05/11/06 10:29 AM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
I think its a misunderstanding.

Yes, you can specify a range of tokens (N-N)
e.g. $gettok(a.b.c.d.e,2-4,46) will return 2nd to 4th token (counted from left, as there is a positive value for N): b.c.d

You can also specify a negative value vor N in $gettok(text,N,C). mIRC will then count the "starting" token not from left, but right.
e.g. $gettok(a.b.c.d.e,-1,46) will return the "first right" token (which is in fact always the last token) : e

To get the last 3 tokens, you can use a range of "third (right) to first (right)" which is: -3 - -1
e.g. $gettok(a.b.c.d.e,-3--1,46) will return (as it should): c.d.e

So far, so good.
What you did, is using a positive AND negative value for N. mIRC dont likes that (I dont know why smile I guess the reason is that mIRC would have to count twice: left AND right).

I'm not sure whether your "$gettok(a.b.c.d.e,2--1,46)" is intended to get "2nd to 2nd-last" token or "2nd to last". If I'm right, you wanted to get "second (counted from left) to first (counted from right) token", that is 2nd to last, that is $gettok(a.b.c.d.e,2-,46) .
Whatever, mIRC dislikes this, and ignores the whole "--1" in $gettok(a.b.c.d.e,2--1,46) as it would ignore "--" in $gettok(a.b.c.d.e,2--,46) or "--nothing" in $gettok(a.b.c.d.e,2--nothing,46) .

If you intend - on the other hand side - to stop at the 2nd-last token, get "b.c.d" counting either
from left: $gettok(a.b.c.d.e,2-4,46)
or
from right: $gettok(a.b.c.d.e,-4--2,46)

Or, If you dont know what number of tokens "text" in fact contains, count them first using $numtok(text,C) or $gettok(text,0,C) .
e.g. to get "2nd to 2nd-last out of a unknown number of tokens":
var %2nd.last = $calc($numtok(text,C) -1)
gettok(text,2- %2nd.last,C)

Hope I could help a little, or at least confused you not even more...

#163852 05/11/06 11:42 AM
Joined: Oct 2006
Posts: 166
B
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
It might not to be a bug for me but you need to specify a corrct range or do some math (workaround)

Code:
alias _gettok if ($regex($2,/(\d\-)\-(\d)/)) return $left($gettok($1,$regml(1),$3),$+(-,$calc($regml(2) *2)))


Kind Regards, blink
#163853 05/11/06 09:59 PM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I could've sworn (although I'm unable to find the code that I used this in), that I could use %token = $gettok(a.b.c.d.e,2--1,46) and it would return the equivalent of
%token = $gettok(a,b,c,d,e,2-,46)
%token = $gettok(%token,-1,46)

or as you put it, 2nd to 2nd last (since -1 returns the 2nd last item)

Oh well, at least I'm aware of an easy work around (as shown above).

#163854 05/11/06 11:25 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I like $deltok($gettok(a.b.c.d.e,2-,46),-1,46) a little better since that gets you b.c.d and not e

#163855 05/11/06 11:39 PM
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
You can use -- smile
//echo -a $gettok(a b c d e f g,-5--3,32)
will return c d e as the range indicates from 5th last to the third last.
//echo -a $gettok(a b c d e f g,-5-3,32)
will return
c d e f g
as it's basicly the same as
//echo -a $gettok(a b c d e f g,-5-,32)

2--1 always returned just b in the example you provided but it sounds like a legit range to me and should be supported in my opinion.

//echo -a $gettok(a b c d e f g,-5--8,32)
//echo -a $gettok(a b c d e f g,2--1,32)
Might have something to with mIRC internal routine as it seems the first value has to be lower then the 2nd.
Probably sets a pointer to the first and add onwards to reading to the right.
A "while rangenumber1 <= rangenumber2" kinda thing that wont trigger when the ragenumber2 is smaller and simply return the ragenumber1 token.

Since when is -1 2nd last though ?


$maybe
#163856 06/11/06 12:49 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I thought it looked like a valid range. It looks like you're right about the first value having to be lower than the second value.
I guess it's using something like a while loop with a built-in increase, so that the loop returns the first item but nothing else (when using //echo -a $gettok(a b c d e f g,2--1,32) )

My apologies regarding -1 being the second last item, as it's obviously the last item, but in the example (if it worked like I thought it would), it would return from the 2nd to the 2nd last characters (which is where I was getting my 2nd last from).

#163857 06/11/06 05:31 AM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
If first value has JUST to be lower than the second, $gettok(a.b.c.d.e,-1-3,46) should work -in theory- too wink but thats nit-picking...

Last edited by Horstl; 06/11/06 05:34 AM.
#163858 06/11/06 05:53 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
So much for theory. Actual test using that code just returns the same as using just -1

#163859 06/11/06 06:02 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
$gettok(a.b.c.d.e,-1-3,46)

that -1 is a negitive index so is infact a larger number -1 here = 5


Link Copied to Clipboard