static string compressedResult = "";
public static void Main()
string str1 = "aaabccccdd";
if (str1 != null && str1.Length > 1)
for (int i = 1; i <= str1.Length-1; i++)
if (str1[i - 1] == str1[i])
Program.computeResult(str1[i-1], counter);
Program.computeResult(str1[i - 1], counter);
if (i == str1.Length - 1)
Program.computeResult(str1[i], counter);
Console.WriteLine(compressedResult);
public static void computeResult(char str, int counter)
compressedResult += str.ToString();
compressedResult += str.ToString() + counter.ToString();