mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
$gettok(text,N,C,T)

Same as before... returns a token or range of tokens, but terminates at T character.

Examples:
$gettok(beverly hills,ca:90210,1,44,58) returns ca
$gettok(somdumfoo!~mycompute@aol.sux,1,33,64) returns mycompute
$gettok(a(97) b(98) c(99),2,40,41) returns 98

Concerning N containing a negative value, meaning that the string is read from right to left... it's my feeling that the T terminating character should still terminate on the right-hand side.
$gettok(<b>this <i>is</i> a test</b>,-2,60,62) returns /i and not is

Another issue at hand, is how to define "Terminating" for N values of 1- or 2- or even 3-5?
Should it simply stop processing when (and if) it hits T?
$gettok(ACTION this is an odd examplePING 1053595552,2-,32,1) returns this is an odd example
Or should it handle the terminating delimiter like so? (most likely)
$gettok(a(97) b(98) c(99),1-,40,41) returns 979899

But what about this case?
$gettok(&(38) '(39) ((40) )(41) *(42),2-3,40,41) returns 39 or 39(40
In the first example (most likely), the $null between (( is being considered as the third token... while in the second example, the identifier wont incriment the token position until T has been hit, treating the ( in (40 as plain text.

That's all I can think of regarding this new parameter. I know with Regular Expressions things like this have become somewhat easier, but I've always felt this has been a missing parameter from the suite of Token Identifiers.

This new parameter should be added to the following Token Identifiers.
$deltok, $findtok, $gettok, $istok, $matchtok, $numtok, $puttok, $remtok, $reptok, $wildtok.

And probably has no use in these Token Identifiers (that I can think of).
$addtok, $instok, $sorttok.

- Raccoon


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
That would be useful, but couldn't you already do that with a combination of $gettok?

$gettok($gettok(somdumfoo!~mycompute@aol.sux,1,64),2,33) = ~mycompute (I assume it was a type that you left off the ~ in the result from your suggestion?)

Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
Yes, but it would be nice to not have to combine gettok's


-KingTomato
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Not saying it wouldn't, I just mean, wouldn't it be trivial to script this?

alias mygettok {
return $gettok($gettok($1,$2,$4),2,$3)
}

That worked for the 3 examples he included.

Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
$mygettok(a(97) b(98) c(99),1,40,41) returns 97
$mygettok(a(97) b(98) c(99),2,40,41) returns 98
$mygettok(a(97) b(98) c(99),1-,40,41) returns 97 b
$mygettok(a(97) b(98) c(99),-2-,40,41) returns 98) c


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
You're right, I didn't make it handle that case for a simple reason... thats not how tokenization works. If you want to do advanced processing like that, well thats what $regex and $regsub are for.

Joined: Feb 2003
Posts: 2,812
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
I know, that's one thing I haven't been able to come up with the proper logic for. That's why I'm increasingly leaning toward the handling prortrayed in this example (from my earlier post).

$gettok(ACTION this is an odd examplePING 1053595552,2-,32,1) returns this is an odd example

Its simple, makes sense... pretty much follows the logic of the token identifiers. The object of $gettok isn't to extract the delimiters themselves, but to extract the data between two endpoints.

I also think T simply gives a person more flexability in what that endpoint is going to be.

- Raccoon

PS. Your $mygettok gives very very weird results on this example too, I can barely wrap my mind around it at this hour.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Well I just started playing around with the regex to do this, but in order to make one that would work allowing you to specify any "range" of elements, it was such a huge regex that it sort of became futile. Maybe I'll play around with my alias some more...


Link Copied to Clipboard