in reply to Re: Remove repeated characters from a string
in thread Remove repeated characters from a string

I wish to remove all repeating letters no matter where they are. I generating a key and can have no double letters at a max there can be 26 letters all unique
  • Comment on Re:^2 Remove repeated characters from a string

Replies are listed 'Best First'.
Re:^3 Remove repeated characters from a string
by Limbic~Region (Chancellor) on May 13, 2004 at 14:54 UTC
    Anonymous Monk,
    Then it sounds like the code I provided is on the right track. It would need to be modified a bit to take into account your additional requirements. Again, this is why it is important to explain your problem without assuming things are just "understood".
    #!/usr/bin/perl use strict; use warnings; my $string = 'One bright day in the middle of The Night'; my (%seen, $new_string); for my $char ( split // , $string ) { $char = lc $char; next if $seen{$char} || $char !~ /^[a-z]$/; $seen{$char}++; $new_string .= $char; last if length $new_string == 26; } print "$new_string\n";
    I hope this helps - L~R
Re: Re:^2 Remove repeated characters from a string
by CountZero (Bishop) on May 14, 2004 at 05:29 UTC
    Interesting, ...

    Why is it that the key may not have repeating characters?

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law