mIRC Home    About    Download    Register    News    Help

Topic Options
#264565 - 15/12/18 02:28 PM duplicate data in a var
Tiago Offline
Vogon poet

Registered: 05/07/14
Posts: 112
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 (IRCop)

Top
#264566 - 15/12/18 02:41 PM Re: duplicate data in a var [Re: Tiago]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3475
Loc: France
use $addtok to add to the variable

//echo -a $addtok(test,test,32)
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#264567 - 15/12/18 02:46 PM Re: duplicate data in a var [Re: Wims]
Tiago Offline
Vogon poet

Registered: 05/07/14
Posts: 112
Originally Posted By: Wims
use $addtok to add to the variable

//echo -a $addtok(test,test,32)

This is not for what I need
_________________________
TECO
irc.PTirc.org (IRCop)

Top
#264568 - 15/12/18 02:56 PM Re: duplicate data in a var [Re: Tiago]
Wims Offline
Planetary brain

Registered: 31/07/06
Posts: 3475
Loc: France
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) */,)
_________________________
Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net

Top
#264569 - 15/12/18 07:40 PM Re: duplicate data in a var [Re: Wims]
Tiago Offline
Vogon poet

Registered: 05/07/14
Posts: 112
Originally Posted By: Wims
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 (IRCop)

Top
#264577 - 16/12/18 05:59 AM Re: duplicate data in a var [Re: Tiago]
maroon Offline
Hoopy frood

Registered: 12/01/04
Posts: 1098

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

Code:
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


Top
#264583 - 16/12/18 07:52 PM Re: duplicate data in a var [Re: maroon]
Tiago Offline
Vogon poet

Registered: 05/07/14
Posts: 112
Originally Posted By: maroon

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

Code:
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
Thank you maroon wink


Edited by Tiago (16/12/18 07:53 PM)
_________________________
TECO
irc.PTirc.org (IRCop)

Top
#264584 - 16/12/18 10:56 PM Re: duplicate data in a var [Re: Tiago]
Raccoon Offline
Hoopy frood

Registered: 18/02/03
Posts: 2560
Thanks for doing the leg work posting smile Ouims and Saturn helped produce those functions. I bet jaytea too.
_________________________
At least I won lunch.
Good philosophy, see good in bad, I like!

Top