mIRC Home    About    Download    Register    News    Help

Print Thread
$nemove/$nremovecs (or better name) #263603 27/08/18 12:47 AM
Joined: Nov 2004
Posts: 800
Jigsy Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Nov 2004
Posts: 800
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


What do you do at the end of the world? Are you busy? Will you save us?
Re: $nemove/$nremovecs (or better name) [Re: Jigsy] #263604 27/08/18 03:07 AM
Joined: Jan 2004
Posts: 1,180
maroon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,180
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.

Re: $nemove/$nremovecs (or better name) [Re: Jigsy] #263641 31/08/18 05:36 PM
Joined: Jul 2006
Posts: 3,559
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,559
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
Re: $nemove/$nremovecs (or better name) [Re: Jigsy] #263644 31/08/18 08:32 PM
Joined: Apr 2010
Posts: 921
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 921
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
Re: $nemove/$nremovecs (or better name) [Re: FroggieDaFrog] #263646 01/09/18 11:21 AM
Joined: Jul 2006
Posts: 3,559
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,559
I wanted to make this break with one way but couldn't grin
However your $iif is wrong, this code is not working

Last edited by Wims; 01/09/18 11:25 AM. Reason: $iif(\n > %n, \1) should be $iif(\n <= %n, \1)

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: $nemove/$nremovecs (or better name) [Re: Wims] #263648 01/09/18 07:47 PM
Joined: Apr 2010
Posts: 921
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 921
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))
}

Last edited by FroggieDaFrog; 01/09/18 08:19 PM.

I am SReject
My Stuff
Re: $nemove/$nremovecs (or better name) [Re: FroggieDaFrog] #263654 01/09/18 11:14 PM
Joined: Jul 2006
Posts: 3,559
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,559
Ah yeah, well at least it's fixed.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net