|
Joined: May 2003
Posts: 2,265
Hoopy frood
|
OP
Hoopy frood
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
Last edited by pheonix; 30/06/03 04:23 PM.
new username: tidy_trax
|
|
|
|
Joined: Dec 2002
Posts: 169
Vogon poet
|
Vogon poet
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.
|
|
|
|
Joined: May 2003
Posts: 2,265
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 2,265 |
new username: tidy_trax
|
|
|
|
Joined: May 2003
Posts: 2,265
Hoopy frood
|
OP
Hoopy frood
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
|
|
|
|
Joined: Dec 2002
Posts: 169
Vogon poet
|
Vogon poet
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.
|
|
|
|
Joined: May 2003
Posts: 2,265
Hoopy frood
|
OP
Hoopy frood
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
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: Dec 2002
Posts: 169
Vogon poet
|
Vogon poet
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?
|
|
|
|
Joined: May 2003
Posts: 2,265
Hoopy frood
|
OP
Hoopy frood
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
|
|
|
|
Joined: May 2003
Posts: 2,265
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 2,265 |
its ok now, got it thanx
Last edited by pheonix; 30/06/03 05:20 PM.
new username: tidy_trax
|
|
|
|
Joined: May 2003
Posts: 2,265
Hoopy frood
|
OP
Hoopy frood
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
new username: tidy_trax
|
|
|
|
Joined: Dec 2002
Posts: 169
Vogon poet
|
Vogon poet
Joined: Dec 2002
Posts: 169 |
$remove(abcdef,a,c,d,e,f) ?
|
|
|
|
Joined: May 2003
Posts: 2,265
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 2,265 |
that would only work for that example.....
new username: tidy_trax
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
Joined: May 2003
Posts: 2,265
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 2,265 |
i want it for sockread, so i can parse links from a google search.
new username: tidy_trax
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
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?
|
|
|
|
Joined: May 2003
Posts: 2,265
Hoopy frood
|
OP
Hoopy frood
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 no look so far....
new username: tidy_trax
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,809 |
Why not use regex?
/<A HREF="*(.+?)"*>/i
That will give you the URL.
|
|
|
|
Joined: May 2003
Posts: 2,265
Hoopy frood
|
OP
Hoopy frood
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
|
|
|
|
Joined: Dec 2002
Posts: 2,809
Hoopy frood
|
Hoopy frood
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.
|
|
|
|
|