Hi, does anyone know of a quick and easy way to make a string only contain one of each character (case sensitive)?
For example i want to turn AAaaBBccCC into AaBbCc
Thanks ![]()
A TG007 community discussion started by ronnie69.
Hi, does anyone know of a quick and easy way to make a string only contain one of each character (case sensitive)?
For example i want to turn AAaaBBccCC into AaBbCc
Thanks ![]()
Try typing this in your script window.
//echo -a $replace(AAaaBBbbCCcc,AAaaBBbbCCcc,AaBbCc)
"Diplomacy is the art of saying 'Nice doggie' until you can find a rock".-Will Rogers
Thanks for the reply!
Sorry, i should have been more specific, the string is a variable and in no particular order.
Anyone else have any ideas?
The string could be something like...
andHhshabdyPcvjshHP
and i want it to return...
andHhsbyPcvj
(only one instance of each submitted character is returned)
![]()
ask petertje - he seems to be the regex guru of the forum
People are like slinkies; they're generally boring until you push them down stairs
Yea ask him.. ive got no idea
Add these two aliases:
alias removerepeats return $reverse($regsubex($reverse($1),/(.)(?=.*?\1)/g,))
alias reverse {
var %string = $1
return $regsubex($1,/(.)/g,$mid(%string,-\n,1))
}
Then you can use:
//echo -a $removerepeats(andHhshabdyPcvjshHP) = andHhsbyPcvj
If you don't have mIRC 6.17 use this instead:
alias regsubex {
var %a, %b = $regsub($1,$2,$3,%a)
return %a
}
alias removerepeats return $reverse($regsubex($reverse($1),/(.)(?=.*?\1)/g,))
alias reverse {
var %i = 1, %value
while ($mid($1,%i,1) != $null) {
%value = $v1 $+ %value
inc %i
}
return %value
}
Nice work hixxy.
alias remreps {
var %i, %j = $regsub($1,/(.)/g,\1 $+ $chr(1),%i), %j = $remove($sorttokcs(%i,1),$chr(1))
%i = $regsub(%j,/(.)(?=.*?\1)/g,,%j)
return %j
}
Thanks. ltns btw ![]()
Wow thanks guys!
Out of interest, what is the difference between the codes and is one more effective than the other, e.g which is faster (if any) ?
No idea which would be faster. I would say test it ![]()
Mine has a sorttok in it so can be slower.
Depends on where you use it for but I dont expect huge differences.
Peter's is a lot faster.
My 6.17 (1000 iterations): 750 MS.My 6.16 (1000 iterations): 1140 MS.
Peter's (1000 iterations): 219 MS.
My 6.17 (1000 iterations): 750 MS.
My 6.16 (1000 iterations): 1125 MS.
Peter's (1000 iterations): 219 MS.
I believe my $reverse alias slows it down a lot.
Thanks ![]()
Wow. Didn't expect that. Must be the $reverse indeed.
Sign in to reply or start a new topic where your account has permission.