Reputation: 359
how can I split a word into characters and then sum all of the ASCII codes to get an integer sum?
Upvotes: 0
Views: 1629
Reputation: 53958
Uisng LINQ, this can be done as below (input
is your string):
var sum = input.Sum(ch=>(int)ch);
Otherwise you could use a foreach
statement and loop through the string's characters:
var sum = 0;
foreach(var ch in input)
{
sum += (int)ch;
}
Upvotes: 6