ronnie69 Posted March 9, 2006 Report Share Posted March 9, 2006 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 Link to comment Share on other sites More sharing options...
Mail Posted March 9, 2006 Report Share Posted March 9, 2006 Try typing this in your script window. //echo -a $replace(AAaaBBbbCCcc,AAaaBBbbCCcc,AaBbCc) Link to comment Share on other sites More sharing options...
ronnie69 Posted March 9, 2006 Author Report Share Posted March 9, 2006 Thanks for the reply! Sorry, i should have been more specific, the string is a variable and in no particular order. Link to comment Share on other sites More sharing options...
ronnie69 Posted March 11, 2006 Author Report Share Posted March 11, 2006 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) Link to comment Share on other sites More sharing options...
Angelia Posted March 11, 2006 Report Share Posted March 11, 2006 ask petertje - he seems to be the regex guru of the forum Link to comment Share on other sites More sharing options...
Gazzy Posted March 11, 2006 Report Share Posted March 11, 2006 Yea ask him.. ive got no idea Link to comment Share on other sites More sharing options...
hixxy Posted March 12, 2006 Report Share Posted March 12, 2006 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 } Link to comment Share on other sites More sharing options...
Pete®tje Posted March 12, 2006 Report Share Posted March 12, 2006 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 } Link to comment Share on other sites More sharing options...
hixxy Posted March 12, 2006 Report Share Posted March 12, 2006 Thanks. ltns btw Link to comment Share on other sites More sharing options...
ronnie69 Posted March 12, 2006 Author Report Share Posted March 12, 2006 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) ? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now