计算字符串行中值的出现次数[关闭]

I have a row like this: a a b b b a b a a b b I need code to print this out: 2a 3b 1a 1b 2a 2b

How to do that in c#

EDIT I need the values to be counted like this: there are 2 of a then 3 of b then 1 of a then 1 of b then 2 of a then 2 of b. I don't need to count occurrences of a and b in total.

I am reading a matrix, value by value diagonally: If I have matrix like this:

 a a b a
 a b a b
 a b b a

I managed to read matrix from the bottom right corner - up and to put values in rows:

1row: a
2row: bb
3row: baa
4row: bba
5row: aa
6row: a

But I need this to look like this:

1row: 1a
2row: 2b
3row: 1b2a
4row: 2b1a
5row: 2a
6row: 1a

Here is a RegEx approach

string input = "aabbbabaabb";
string result = string.Concat(Regex.Matches(input, @"(.)\1*", RegexOptions.None)
                      .Cast<Match>()
                      .Select(x => string.Concat(x.Length, x.Value.First())));