|
Joined: Apr 2010
Posts: 969
Hoopy frood
|
OP
Hoopy frood
Joined: Apr 2010
Posts: 969 |
Using $pos(text, string, N) Currently, if N <= 0, $pos returns the number of occurrences of string in text. With other string identifiers such as $left(), $mid(), $right(), $*tok, etc a negetive N causes the identifier to work in reverse. It would be handy if $pos() would support such reversed behavior aswell Example:
$pos(abccba, a, -1) - returns 6
|
|
|
|
Joined: Jul 2006
Posts: 4,222
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,222 |
Probably has been suggested many times in the past, still a good idea.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jan 2012
Posts: 337
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Jan 2012
Posts: 337 |
As a solution I created a self-written identifier for you: $posmir (position mirror) ‒ returns the position of found characters in the string in reverse order. Syntax: $posmir(text,string,N) ‒ If it is convenient for you to specify negative values ( N = -1) in your script, then it will work in the same way (analogically) as with numbers greater than zero. Example1: $posmir(abccba abca cbcba,bc,0) ‒ Returns: 3Example2: $posmir(abccba abca cbcba,bc,1) ‒ Returns: 14Example3: $posmir(abccba abca cbcba,bc,3) ‒ Returns: 2Example4: $posmir(abccba␣abca␣cbcba,$chr(32),0) ‒ Returns: 2Example5: $posmir(abccba abca␣cbcba,$chr(32),1) ‒ Returns: 12
alias posmir {
if (($1 != $null) && ($2 != $null) && ($3 != $null)) {
if ($3 == 0) return $pos($1,$2,$3)
var %pm1 $1 | var %pm2 $2 | var %pm3 $remove($3,-)
var %pm_a $pos(%pm1,%pm2,0)
var %pm_c $calc(%pm_a +1 - %pm3)
var %pm_p $pos(%pm1,%pm2,%pm_c)
if (%pm3 <= %pm_a) return %pm_p | else return 0
}
echo -sc info * insufficient parameters ‒ $+(correct syntax:,$color(notice).dd) $eval($posmir(text,string,N),0) | halt
}
Testing commands:
//echo -a $posmir(abccba abca cbcba,bc,0)
//echo -a $posmir(abccba abca cbcba,bc,1)
//echo -a $posmir(abccba abca cbcba,bc,3)
//echo -a $posmir(abccba abca cbcba,$chr(32),0)
//echo -a $posmir(abccba abca cbcba,$chr(32),1)
This is probably what you would like to see. Though I also support your idea for realization negative values in built-in identifier " $pos".
Last edited by Epic; 28/05/21 04:33 PM. Reason: changes in code after comment from maroon
|
|
|
|
Joined: Jan 2004
Posts: 2,127
Hoopy frood
|
Hoopy frood
Joined: Jan 2004
Posts: 2,127 |
Just a minor point. Identifier calls should not return a string containing the error message. It should instead be echoed and the script halted. return $+(,$color(info).dd,*) insufficient parameters - $+(correct syntax:,$color(notice).dd) $eval($posmir(text,string,N),0) should become something like: echo -sc info insufficient parameters - $+(correct syntax:,$color(notice).dd) $eval($posmir(text,string,N),0)
halt
Unfortunately, an error message could only report a script/scriptline for the location of your alias. Without something like the previously requested $calias, it's not possible to report the scriptline/scriptname of the calling alias unless they're passed along as the $4 and $5 parms.
|
|
|
|
Joined: Apr 2010
Posts: 969
Hoopy frood
|
OP
Hoopy frood
Joined: Apr 2010
Posts: 969 |
I currently use the following: alias posx {
if ($3 >= 0 || $calc($3+1+ $count($1,$2)) > 0) {
return $pos($1,$2,$v1)
}
} Edited: Tinkered with the alias a bit to make it shorter
Last edited by FroggieDaFrog; 28/05/21 04:07 PM.
|
|
|
|
Joined: Jan 2012
Posts: 337
Pan-dimensional mouse
|
Pan-dimensional mouse
Joined: Jan 2012
Posts: 337 |
You're right. The identifier doesn't really need to return an error if multiple parameters are missing on run. It is enough to notify about this in an echo message and halted the script. Therefore this line should be replaced: return $+(,$color(info).dd,*) insufficient parameters ‒ $+(correct syntax:,$color(notice).dd) $eval($posmir(text,string,N),0) Replace with this line: echo -sc info * insufficient parameters ‒ $+(correct syntax:,$color(notice).dd) $eval($posmir(text,string,N),0) | halt Thank you for your help with the hint 
|
|
|
|
|