mIRC Home    About    Download    Register    News    Help

Topic Options
#263603 - 27/08/18 01:47 AM $nemove/$nremovecs (or better name)
Jigsy Offline
Hoopy frood

Registered: 18/11/04
Posts: 799
Loc: I live inside your computer. S...
Since changing $remove/$removecs would break compatability afaik, this would most likely need to be a new function.

What I'm proposing is something like $remove, but with the option to remove only a number of relevant characters.

E.g. $nremove(ooohv, 1, o) > oohv
_________________________
This signature is currently out of order. We apologize for the inconvenience.

Top
#263604 - 27/08/18 04:07 AM Re: $nemove/$nremovecs (or better name) [Re: Jigsy]
maroon Offline
Hoopy frood

Registered: 12/01/04
Posts: 1158
Just to clarify, it seems you want to remove only the first N matches?

Something like this?

//echo -a $regsubex(ooohv,/o/gi,$iif(\n <= 1,$null,o) )

Changing the 1 would determine how many matches would be removed.

Top
#263641 - 31/08/18 06:36 PM Re: $nemove/$nremovecs (or better name) [Re: Jigsy]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3515
Loc: France
You're not mentioning that a while loop on the N parameter + doing a remove in the loop is not an option for you. This is easily scripted, are you looking for mIRC to do the loop for extra efficiency?
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#263644 - 31/08/18 09:32 PM Re: $nemove/$nremovecs (or better name) [Re: Jigsy]
FroggieDaFrog Online
Hoopy frood

Registered: 16/04/10
Posts: 910
Loc: USA
Code:
alias -l regesc {
  return \Q $+ $replacecs($3, \E, \E\\E\Q) $+ \E
}

alias nremove {
  var %n = $2
  return $regsubex($1, /( $+ $regesc($3) $+ )/ugi, $iif(\n > %n, \1))
}

alias nremovecs {
  var %n = $2
  return $regsubex($1,/( $+ $regesc($3) $+ )/ug, $iif(\n > %n, \1))
}
_________________________
I am SReject
My Stuff

Top
#263646 - 01/09/18 12:21 PM Re: $nemove/$nremovecs (or better name) [Re: FroggieDaFrog]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3515
Loc: France
I wanted to make this break with one way but couldn't grin
However your $iif is wrong, this code is not working


Edited by Wims (01/09/18 12:25 PM)
Edit Reason: $iif(\n > %n, \1) should be $iif(\n <= %n, \1)
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#263648 - 01/09/18 08:47 PM Re: $nemove/$nremovecs (or better name) [Re: Wims]
FroggieDaFrog Online
Hoopy frood

Registered: 16/04/10
Posts: 910
Loc: USA
The idea is to remove the first n occurrences of the 'match'; not keep the first n occurrences, thus there isn't a 'bug' in the iif.

Example:
Code:
Should remove the first 2 occurances
    $nremove(abab-abab, 2, ab) 

resulting in
    -abab


However, there is a typo/bug in $regesc where $3 should be $1:

Code:
alias -l regesc {
  return /(\Q $+ $replacecs($1, \E, \E\\E\Q) $+ \E)/ug $+ $prop
}

alias nremove {
  var %n = $2
  return $regsubex($1, $regesc($3).i, $iif(\n > %n, \1))
}

alias nremovecs {
  var %n = $2
  return $regsubex($1, $regesc($3), $iif(\n > %n, \1))
}


Edited by FroggieDaFrog (01/09/18 09:19 PM)
_________________________
I am SReject
My Stuff

Top
#263654 - 02/09/18 12:14 AM Re: $nemove/$nremovecs (or better name) [Re: FroggieDaFrog]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3515
Loc: France
Ah yeah, well at least it's fixed.
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top