How to count the occurrence of no of char in
a string and asci value of char 
For example:
Input : ShivKumarSingh 
OutPut : 
S =  Ascii Value = 83
and Count = 4
h =  Ascii Value = 104
and Count = 2
i =  Ascii Value = 105
and Count = 2
v =  Ascii Value = 118
and Count = 1
K =  Ascii Value = 75
and Count = 1
u =  Ascii Value = 117
and Count = 1
m =  Ascii Value = 109
and Count = 1
a =  Ascii Value = 97
and Count = 1
r =  Ascii Value = 114
and Count = 1
n =  Ascii Value = 110
and Count = 1
g =  Ascii Value = 103
and Count = 1 
  public static void CountAccurance(String str)
        {
            char[] ch = str.ToCharArray();
            for (int i = 0; i <= str.Length - 1; i++)
            {
                if (ch[i] != '0')
                {
                    int count = 1;
                    for (int j = i + 1; j <= str.Length - 1; j++)
                    {
                        if (char.ToUpper(ch[i]) == char.ToUpper(ch[j]))
                        {
                            count++;
                            ch[j] = '0';
                        }
                    }
                    Console.WriteLine(ch[i] + " =  Ascii Value = "+ Convert.ToInt32(ch[i]) +" and Count = " + count);
                }
               
            }
        }
 




 

 
 
 
 
 Posts
Posts
 
 
No comments:
Post a Comment