how to read char from a string in c#
<p>I have a string <code>a = "aabbbffdshhh"</code>.  I want to write a program which will give me output of <code>"a2b3f2d1s1h3"</code>.  I want to return each letter in the alphabet present and it's count.</p>

<p>The code I am currently using is:</p>

<pre><code>int cnta;int cntb; int cntf; int cnth;

for (int i=0;i&lt;a.lenghth;i++)
{
   if(a[i]=='a')
   {
      cnta++;
   }
   if(a[i]=='b')
   {
      cntb++;
   }
   if(a[i]=='h')
   {
   cnth++;
   }
}
</code></pre>

<p>It is giving me the output but this logic not good.  What other algorithms or approaches could I use?</p>
