protected void Compress() { char[] chars = RawString.ToCharArray(); StringBuilder builder = new StringBuilder(); int count = 1; char previous = chars[0]; for (int i = 1; i < chars.Length; i++) { char current = chars[i]; if (current == previous) { count++; } else { if (count > 1) { builder.Append(count); } builder.Append(previous); count = 1; } previous = current; } if (count > 1) { builder.Append(count); } CompressedString = builder.Append(previous).ToString(); }