string str = "W,e,l,c,o,m,e,t,o C,h,i,n,a,w,o,r,l,d"; ;
string[] arry = str.Split(',');
Dictionary<string, int> st = new Dictionary<string, int>();
foreach (string w in arry)
{
if (st.ContainsKey(w))
{
st[w] += 1;
}
else
{
st[w] = 1;
}
}
foreach (var kv in st)
{
Console.WriteLine(string.Format("{0}:{1}", kv.Key, kv.Value));
}
Console.ReadKey(); |