Removing long strands of letters that are the same

Diablicolic

Centurion
Joined
Jul 28, 2003
Messages
167
Location
Your Neighbor
I have this problem with a string, you see it always seems to come out like something like this:

hhheeellllloooooo

And I was wondering if there was a way to like delete the extras so that it would come out looking like this:

helo

:)
 
You could do this:
C#:
for (int i = 0; i <= 26; i++) {
  String lc = Convert.ToChar(i + 97).ToString();
  String uc = Convert.ToChar(i + 65).ToString();

  // Replace twice so that triplets are reduced to 1:
  // 1) aaaaaa -> aaaa
  // 2) aaaa -> a
  myText = myText.Replace(lc + lc, lc).Replace(lc + lc, lc);
  myText = myText.Replace(uc + uc, uc).Replace(uc + uc, uc);
}
A bit hackish I suppose, but it should work (I haven't tested it though).
 
Back
Top