int lastDigit = 0;
int sum = ISSN.Sum(c => char.IsDigit(c) ? lastDigit = (int)c - (int)'0' : 0);
sum -= lastDigit;
int mod = sum % 11;
int checkDigit = 0;
if (mod != 0)
checkDigit = 11 - mod;
if (checkDigit == lastDigit)
{
}
The example you gave (0378-5955) appears to be of an
invalid ISSN.
The check digit should be 4.
[Edit: since you didn't describe the algorithm correctly, the above didn't do the right thing, so I'll fix it.]
int lastDigit = 0;
int digitPosition = 8;
int sum = ISSN.Sum(c => {
if (!char.IsDigit(c))
return 0;
lastDigit = (int)c - (int)'0';
return digitPosition-- * lastDigit;
});
if (digitPosition != 0)
throw new ArgumentException("Incorrect number of digits in ISSN");
sum -= lastDigit;
int mod = sum % 11;
int checkDigit = 0;
if (mod != 0)
checkDigit = 11 - mod;
if (checkDigit == lastDigit)
{
}