|
Joined: Jul 2014
Posts: 317
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Jul 2014
Posts: 317 |
Hi I have a %var as follows:
PTirc PTirc PTirc PTirc PTnet PTnet PTnet PTnet PTnet PTnet PTnet
I no longer remember how I can filter this and make the var return only one word:
Example: PTirc PTnet
Does anyone know how to do it?
TECO irc.PTirc.org (Co-Admin)
|
|
|
|
Joined: Jul 2006
Posts: 4,150
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,150 |
use $addtok to add to the variable
//echo -a $addtok(test,test,32)
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jul 2014
Posts: 317
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Jul 2014
Posts: 317 |
use $addtok to add to the variable
//echo -a $addtok(test,test,32) This is not for what I need
TECO irc.PTirc.org (Co-Admin)
|
|
|
|
Joined: Jul 2006
Posts: 4,150
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,150 |
How are you getting that variable with such a value?
You can use $regsubex(PTirc PTirc PTirc PTirc PTnet PTnet PTnet PTnet PTnet PTnet PTnet,/(\w+)(?=.*\b\1\b) */,)
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Jul 2014
Posts: 317
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Jul 2014
Posts: 317 |
How are you getting that variable with such a value?
You can use $regsubex(PTirc PTirc PTirc PTirc PTnet PTnet PTnet PTnet PTnet PTnet PTnet,/(\w+)(?=.*\b\1\b) */,) Yes, I am getting this value in a variable, but I intend to remove all repeated words and that the final result is, it gets one of each. Example. Final result: PTirc PTnet
TECO irc.PTirc.org (Co-Admin)
|
|
|
|
Joined: Jan 2004
Posts: 2,127
Hoopy frood
|
Hoopy frood
Joined: Jan 2004
Posts: 2,127 |
Thanks to Raccoon for these aliases. Obviously 32 is the codepoint for the space delimiter. If you're not concerned with the order in which the tokens appear, you can just do: //var %a ab cd ef gh ij ab ab ef | echo -a $dedupetok(%a,32) which returns: cd gh ij ab ef ... which is the order after deleting the leftmost dupes. If you want to make it get rid of the rightmost dupes, you have to flip the word order, then kill the leftmost dupes, then flip it again: //var %a ab cd ef gh ij ab ab ef | echo -a $revtok($dedupetok($revtok(%a,32),32),32) returns: ab cd ef gh ij
alias revtok { var %a = $1, %b = $2 | return $regsubex(_revtok,%a,/[^ $+ $chr(%b) $+ ]+/g,$gettok(%a,-\n,%b)) } ; by Raccoon 2017
alias dedupetok { return $regsubex(_dedupetok,$1,$replace(/(?<=^|x)x*+(?:([^x]++)x++(?=(?:.*?x)??\1(?:x|$)))?|x+$/g,x,\Q $+ $chr($$2) $+ \E),) } ; by Raccoon Ouims Saturn 2017
|
|
|
|
Joined: Jul 2014
Posts: 317
Pan-dimensional mouse
|
OP
Pan-dimensional mouse
Joined: Jul 2014
Posts: 317 |
Thanks to Raccoon for these aliases. Obviously 32 is the codepoint for the space delimiter. If you're not concerned with the order in which the tokens appear, you can just do: //var %a ab cd ef gh ij ab ab ef | echo -a $dedupetok(%a,32) which returns: cd gh ij ab ef ... which is the order after deleting the leftmost dupes. If you want to make it get rid of the rightmost dupes, you have to flip the word order, then kill the leftmost dupes, then flip it again: //var %a ab cd ef gh ij ab ab ef | echo -a $revtok($dedupetok($revtok(%a,32),32),32) returns: ab cd ef gh ij
alias revtok { var %a = $1, %b = $2 | return $regsubex(_revtok,%a,/[^ $+ $chr(%b) $+ ]+/g,$gettok(%a,-\n,%b)) } ; by Raccoon 2017
alias dedupetok { return $regsubex(_dedupetok,$1,$replace(/(?<=^|x)x*+(?:([^x]++)x++(?=(?:.*?x)??\1(?:x|$)))?|x+$/g,x,\Q $+ $chr($$2) $+ \E),) } ; by Raccoon Ouims Saturn 2017
Thank you Raccoon ![wink wink](/images/graemlins/mirc/wink.gif) Thank you maroon
Last edited by Tiago; 16/12/18 07:53 PM.
TECO irc.PTirc.org (Co-Admin)
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
Thanks for doing the leg work posting ![smile smile](/images/graemlins/mirc/smile.gif) Ouims and Saturn helped produce those functions. I bet jaytea too.
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
|