in reply to Remove repeated characters from a string

Anonymous Monk,
The short answer is yes. The long answer is yes, but which simple line of code all depends on what you mean. That is why it is important not to leave ambiguity in your questions. It is frustrating to have people answer questions you did not ask. So as to not leave you with all questions and no answers. Take a look at this small snippet, it should help if what you are going for is option 3. It is intentionally "wordy" so that the process is more obvious.
#!/usr/bin/perl use strict; use warnings; my $string = 'one bright day in the middle of the night'; my (%seen, $new_string); for ( split // , $string ) { next if $seen{$_}; $seen{$_}++; $new_string .= $_; } print "$new_string\n";
Cheers - L~R

Replies are listed 'Best First'.
Re:^2 Remove repeated characters from a string
by Anonymous Monk on May 13, 2004 at 14:47 UTC
    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
      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
      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