mIRC Homepage
Posted By: pheonix token alias - 30/06/03 04:19 PM
alias toknum {
var %i 1
while (%i <= $len($gettok($1-,1,44))) {
if ($gettok($1-,2,44) == $mid($gettok($1-,1,44),%i,1)) {
return %i
}
inc %i
}
}

i was hoping say for example: i type, //echo -a $toknum(example,p) it will return the number position of the letter in the word, in this case it would return 5, because p is the 5th letter in example.
any help greatly appreciated grin
Posted By: Jerk Re: token alias - 30/06/03 04:26 PM
You mean like $pos() does?

From the help file:
$pos(text,string,N)
Returns a number indicating the position of the Nth occurrence of string in text.

$pos(hello there,e,1) returns 2
$pos(hello there,e,2) returns 9
$pos(hello there,a,1) returns $null

If N is zero, it returns the number of times string appears in text

Also:

Why use $gettok() on $1- when you can just use $1 $2 $3. This works better for custom identifiers because $1 can be more than one word.

$test(this is a test,ignore if you like,1)
$1 = this is a test
$2 = ignore if you like
$3 = 1
$1- = this is a test ignore if you like 1
note that commas are gone when you use $1-
Posted By: pheonix Re: token alias - 30/06/03 04:30 PM
ok thanx
Posted By: pheonix Re: token alias - 30/06/03 04:35 PM
another alias,

alias surtok {
var %i 1
while (%i <= $gettok($1-,1,44)) {
if ($mid($gettok($1-,1,44),%i,1) == $gettok($1-,2,44)) {
return $mid($pos($mid($gettok($1-,1,44),%i,1) - 1)),1) $mid($pos($mid($gettok($1-,1,44),%i,1) + 1),1)
}
inc %i
}
}

i was hoping if i type $surtok(abc,b) it will return ac because thats the tokens that surrounds b
thanx for any help.
Posted By: Jerk Re: token alias - 30/06/03 04:59 PM
I don't quite understand that one. In your example $surtok(abc,b) what is the token seperator? Is b supposed to be the seperator or is b supposed to be one of the tokens? I could use a clearer explanation and perhaps more examples.
Posted By: pheonix Re: token alias - 30/06/03 05:05 PM
basically i want $surtok(abc,b) to return ac because of the ,b it means i want the token each side of that in the text given, in this case abc so therefore
abc is the whole string >(abc,b) < i want to find the letters that surround this in this case b.
Posted By: codemastr Re: token alias - 30/06/03 05:14 PM
Those are not tokens, they are characters, there is a signifigant difference. So in any case, something like:

return $mid($1-,$calc($pos($1-,$2,1)-1),1) $+ $mid($1-,$calc($pos($1-,$2,1)+1),1)

should do what you want. It will return the characters (if any) that are before and after the matched character.

*** Editted, realized I had a typo.
Posted By: Jerk Re: token alias - 30/06/03 05:15 PM
I was hoping for additional examples. What should it return in these cases:
$surtok(abcdefg,d)
$surtok(a b c d e,b)
$surtok(abcabc,b)

Do you want it to return only one character left and right of your second parameter? What if there is more than one in the string?
Posted By: pheonix Re: token alias - 30/06/03 05:17 PM
$surtok(abcdefg,d) = ce
$surtok(a b c d e,b) =
$surtok(abcabc,b) = ac
Posted By: pheonix Re: token alias - 30/06/03 05:19 PM
its ok now, got it thanx smile
Posted By: pheonix Re: token alias - 30/06/03 05:31 PM
oops i did it the wrong way round, i want to type $surtok(abcdef,acdef) to return b, because thats the character that surrounded by them, any ideas grin
Posted By: Jerk Re: token alias - 30/06/03 06:31 PM
$remove(abcdef,a,c,d,e,f) ?
Posted By: pheonix Re: token alias - 30/06/03 07:22 PM
that would only work for that example.....
Posted By: codemastr Re: token alias - 30/06/03 07:43 PM
Why exactly do you want such a thing? It really doesn't make sense to me, and even if you really do need it, doing that is going to be a very slow algorithm. You're going to have to do some elementary subexpression matching which can get very ugly very quickly.
Posted By: pheonix Re: token alias - 30/06/03 07:59 PM
i want it for sockread, so i can parse links from a google search.
Posted By: codemastr Re: token alias - 30/06/03 08:09 PM
Hmm well I've seen people who had google scripts before, and I've never seen anyone with an identifier like that. What are you doing exactly?
Posted By: pheonix Re: token alias - 30/06/03 08:15 PM
it returns,

<text><a href=www.somelink.com> etc etc i wanna extract the link from my search, and remove all <tags>, ive been tryin it for month now blush no look so far....
Posted By: codemastr Re: token alias - 30/06/03 08:20 PM
Why not use regex?

/<A HREF="*(.+?)"*>/i

That will give you the URL.
Posted By: pheonix Re: token alias - 30/06/03 08:21 PM
i dont understand regex at all lol.
it makes no sense to me, mirc help dont explain it very well
Posted By: codemastr Re: token alias - 30/06/03 08:23 PM
Yes well the thing is, to do it without regex means you are (basically) going to have to write your own regex parser. And writing your own parser is going to be much more difficult than just learning regex.
Posted By: pheonix Re: token alias - 30/06/03 08:32 PM
anyone have a link to a decent regex/regsub tutorial smile ?
Posted By: codemastr Re: token alias - 30/06/03 08:55 PM
I can't vouch for whether this is good or not, but mircscripts.org seems to have reasonably good tutorials, so give it a look, http://www.mircscripts.org/showdoc.php?type=tutorial&id=989
Posted By: pheonix Re: token alias - 30/06/03 09:19 PM
thanx, that seems pretty helpful smile will i need to use $regex or $regsub though?
Posted By: codemastr Re: token alias - 30/06/03 10:04 PM
Well it depends, do you want to retreive the url, or remove everything except the url from the original string?
Posted By: pheonix Re: token alias - 01/07/03 07:59 AM
either, i can either pull the link out, or remove the rest, but i cant use $remove because it says line too long :tongue:
© mIRC Discussion Forums