mIRC Home    About    Download    Register    News    Help

Print Thread
#162285 16/10/06 03:31 PM
Joined: Oct 2006
Posts: 166
B
b1ink Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
Hi. How about an identifier to remove an occurrence of substring. but single remove. example below:

//if ($remove(aaabb,b)) echo $ifmatch
* above will return aaa as we all now.

//if ($removex(aaabb,b)) echo $ifmatch
* above will just remove the first matched occurrence which will return aaab

I made a worked-around snippet. but I wish to see this feature to be built-in.

Last edited by b1ink; 16/10/06 03:37 PM.

Kind Regards, blink
#162286 16/10/06 03:59 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Nice idea. Better yet, make it $removex(string,sub,N[,sub,N,...]), removing the Nth occurrence of <sub> in <string>. N could be negative (removing from the right) or zero (removing all occurrences).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#162287 16/10/06 04:04 PM
Joined: Oct 2006
Posts: 166
B
b1ink Offline OP
Vogon poet
OP Offline
Vogon poet
B
Joined: Oct 2006
Posts: 166
That's even better qwerty smile


Kind Regards, blink
#162288 16/10/06 11:16 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Just to throw a spanner around the room, should each following "sub,N" be based apon the original string or the resulting string as it stands at the time of reaching the said "sub,N" ?

#162289 16/10/06 11:36 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Heh, good point. Maybe the name $removex should be reserved for the identifier similar to $replacex. I can't come up with a short and descriptive name for this one ($removeone/$removeonex doesn't sound quite right).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#162290 17/10/06 09:47 AM
Joined: Apr 2004
Posts: 759
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
$remove already targets the string as it is when it reaches the nex parameter
$remove(abed,abe,ed)
Would leave Null when you target the input string alone but it returns d because "abe" was removed and ed wasn't found anymore.
$removex() should target the input string alone (like $replacex does) and shouldnt be complicated with N parameters IMO because then $remove and $removex wouldn't work in the same matter as $replace and $replacex .
Maybe $removeps() would be a good name ? and $removepsex() smile ps meaning position sensitive.

Ps: explanation not targeted at anyone in this thread wink

EDIT: Just realised $removepsex() would be subject to jokes and laughter :tongue:

Last edited by Mpdreamz; 17/10/06 10:02 AM.

$maybe
#162291 17/10/06 10:58 PM
Joined: Mar 2003
Posts: 612
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Mar 2003
Posts: 612
/me jokes and laughs...


pee sex haha

btk blush grin smile


billythekid

Link Copied to Clipboard