mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Nov 2004
Posts: 842
Jigsy Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Nov 2004
Posts: 842
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?
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
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.

Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
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?


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
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
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
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)

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
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
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
Ah yeah, well at least it's fixed.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard