http://de.wikipedia.org/wiki/ISBN#ISBN-10
http://en.wikipedia.org/wiki/ISBN#ISBN-10
private static String ConvertISBN13To10(String isbn)
{
Char[] isbn13;
UInt16[] isbn10;
StringBuilder sb;
Int32 checksum;
isbn13 = isbn.ToCharArray();
isbn10 = new UInt16[10];
for(UInt16 i = 3, j = 0; i < 12; i++, j++)
{
isbn10[j] = UInt16.Parse(isbn13[i].ToString());
}
checksum = 0;
sb = new StringBuilder();
for(UInt16 i = 0; i < 9; i++)
{
checksum += isbn10[i] * (i + 1);
sb.Append(isbn10[i].ToString());
}
checksum %= 11;
if(checksum == 10)
{
sb.Append("X");
}
else
{
sb.Append(checksum.ToString());
}
return (sb.ToString());
}
Kommentare zum Snippet