-1

I want to find the sum of ascii values of string. How to do it?

   string value = "9quali52ty3";
  // Convert the string into a byte[].
  byte[] asciiBytes = Encoding.ASCII.GetBytes(value);

I'am getting output as 57 113 117 97 108 105 53 50 116 121 51. Now I want to find the sum of above ascii : 57+113+117+97+108+53+50+116+121+51

user2431727
  • 877
  • 2
  • 15
  • 46

2 Answers2

2

You can simply try this,

string value = "9quali52ty3";
// Convert the string into a byte[].
byte[] asciiBytes = Encoding.ASCII.GetBytes(value);
int total = 0;
Array.ForEach(asciiBytes, delegate (byte i) { total += i; });
Er Suman G
  • 581
  • 5
  • 12
0

Add them using a foreach loop

    string value = "9quali52ty3";
    // Convert the string into a byte[].
    byte[] asciiBytes = Encoding.ASCII.GetBytes(value);

    int total = 0;

    foreach (var i in asciiBytes)
    {
        total += i;
    }
Nelson T Joseph
  • 2,683
  • 8
  • 39
  • 56