Report Offensive Message

Challenge accepted!
How about this (C#) alternative:

static bool IsISBNValid(string sInput)
{
// remove delimiters
string sISBN = Regex.Replace(sInput, @"-|\.| ", "");

// validate number of digits
if (sISBN.Length != 10 && sISBN.Length != 13)
return false;

// calculate the product of the digit multiplication operations
int iProd = 0;
for (int i = 0; i (sISBN.Length - 1); i++)
{
if (sISBN.Length == 10)
iProd += Convert.ToInt16(sISBN.Substring(i, 1)) * (10 - i);
else
iProd += Convert.ToInt16(sISBN.Substring(i, 1)) * (1 + (2 * (i % 2)));
}

// calculate the check digit
string sCheckDigit;
if (sISBN.Length == 10)
{
sCheckDigit = Convert.ToString((11 - (iProd % 11)) % 11);
if (sCheckDigit == "10")
sCheckDigit = "X";
}
else
sCheckDigit = Convert.ToString(10 - (iProd % 10));

// validate check digit
return (sCheckDigit == sISBN.Substring(sISBN.Length - 1, 1));
}
Posted by Tillworks
8th Jun 2007