Sorry. Didn't see that you tagged it with VB.NET
Anyway.. Here's my c# example. Same logic in VB, should be easy to convert..
var text = "aaaabbbbcccdddbbddaaccbbdd";
var values = new Dictionary<string, int>();
for (var i = 0; i < text.Length; i++)
{
var character = text[i].ToString();
if (values.ContainsKey(character))
{
values[character] ++;
}
else
{
values.Add(character, 1);
}
}
var sb = new StringBuilder();
foreach (KeyValuePair<string, int> pair in values)
{
sb.Append(pair.Key + pair.Value);
}
Console.WriteLine(sb.ToString());
Console.Read();
If you want to order values you can loop this way:
foreach (KeyValuePair<string, int> pair in values.OrderBy(a=>a.Key))
{
sb.Append(pair.Key + pair.Value);
}