I have a string that consists of 11 digits(might be more or less at another time). This is too long to convert into an integer so I don't know how to get the sum of the digits.
I have tried:
string numberString = "84610467228";
int sumNumbers = 0;
for (int i = 0; i < numberString.Length; i++) {
sumNumbers = sumNumbers + numberString[i];
}
But this doesn't work because numberString[i] is a char and not an integer.
What I wanted to do, by converting the string into an integer was:
string numberString = "84610467228";
int number = int.Parse(numberString);
int sumNumbers = 0;
for (int i = 0; i < numberString.Length; i++) {
sumNumbers = sumNumbers + number%10;
number = number / 10;
}
But the string is too long to convert into an integer. Is there a way of converting a long string into an integer or is there another way to solve this?