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
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-
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.
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.
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.
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.
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?
$surtok(abcdefg,d) = ce
$surtok(a b c d e,b) =
$surtok(abcabc,b) = ac
its ok now, got it thanx
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
$remove(abcdef,a,c,d,e,f) ?
that would only work for that example.....
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.
i want it for sockread, so i can parse links from a google search.
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?
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....
Why not use regex?
/<A HREF="*(.+?)"*>/i
That will give you the URL.
i dont understand regex at all lol.
it makes no sense to me, mirc help dont explain it very well
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.
anyone have a link to a decent regex/regsub tutorial
?
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
thanx, that seems pretty helpful
will i need to use $regex or $regsub though?
Well it depends, do you want to retreive the url, or remove everything except the url from the original string?
either, i can either pull the link out, or remove the rest, but i cant use $remove because it says line too long :tongue: