mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
#33185 30/06/03 04:19 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
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

Last edited by pheonix; 30/06/03 04:23 PM.

new username: tidy_trax
#33186 30/06/03 04:26 PM
Joined: Dec 2002
Posts: 169
J
Vogon poet
Offline
Vogon poet
J
Joined: Dec 2002
Posts: 169
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-

Last edited by Jerk; 30/06/03 04:33 PM.
#33187 30/06/03 04:30 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
ok thanx


new username: tidy_trax
#33188 30/06/03 04:35 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
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.


new username: tidy_trax
#33189 30/06/03 04:59 PM
Joined: Dec 2002
Posts: 169
J
Vogon poet
Offline
Vogon poet
J
Joined: Dec 2002
Posts: 169
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.

#33190 30/06/03 05:05 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
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.


new username: tidy_trax
#33191 30/06/03 05:14 PM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
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.

Last edited by codemastr; 30/06/03 05:19 PM.
#33192 30/06/03 05:15 PM
Joined: Dec 2002
Posts: 169
J
Vogon poet
Offline
Vogon poet
J
Joined: Dec 2002
Posts: 169
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?

#33193 30/06/03 05:17 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
$surtok(abcdefg,d) = ce
$surtok(a b c d e,b) =
$surtok(abcabc,b) = ac


new username: tidy_trax
#33194 30/06/03 05:19 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
its ok now, got it thanx smile

Last edited by pheonix; 30/06/03 05:20 PM.

new username: tidy_trax
#33195 30/06/03 05:31 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
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


new username: tidy_trax
#33196 30/06/03 06:31 PM
Joined: Dec 2002
Posts: 169
J
Vogon poet
Offline
Vogon poet
J
Joined: Dec 2002
Posts: 169
$remove(abcdef,a,c,d,e,f) ?

#33197 30/06/03 07:22 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
that would only work for that example.....


new username: tidy_trax
#33198 30/06/03 07:43 PM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
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.

#33199 30/06/03 07:59 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
i want it for sockread, so i can parse links from a google search.


new username: tidy_trax
#33200 30/06/03 08:09 PM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
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?

#33201 30/06/03 08:15 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
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....


new username: tidy_trax
#33202 30/06/03 08:20 PM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Why not use regex?

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

That will give you the URL.

#33203 30/06/03 08:21 PM
Joined: May 2003
Posts: 2,265
P
pheonix Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: May 2003
Posts: 2,265
i dont understand regex at all lol.
it makes no sense to me, mirc help dont explain it very well


new username: tidy_trax
#33204 30/06/03 08:23 PM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
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.

Page 1 of 2 1 2

Link Copied to Clipboard