by Fabrice Marguerie via Fabrice's weblog on 12/22/2007 11:37:00 PM
If for some reason you need to convert an ISBN-13 to ISBN-10 (one being that Amazon doesn't support ISBN-13 in product affiliate links) then you need not only to remove the first three characters. You also need to recompute the checksum.
Here is a piece of code that I wrote to handle this conversion:
public static String Isbn13to10(String isbn13){ if (String.IsNullOrEmpty(isbn13)) throw new ArgumentNullException("isbn13"); isbn13 = isbn13.Replace("-", "").Replace(" ", ""); if (isbn13.Length != 13) throw new ArgumentException("The ISBN doesn't contain 13 characters.", "isbn13"); String isbn10 = isbn13.Substring(3, 9); int checksum = 0; int weight = 10; foreach (Char c in isbn10) { checksum += (int)Char.GetNumericValue(c) * weight; weight--; } checksum = 11-(checksum % 11); if (checksum == 10) isbn10 += "X"; else if (checksum == 11) isbn10 += "0"; else isbn10 += checksum; return isbn10;}
I use this to create the Amazon affiliate links on Clair de Bulle, the famous French comics website of my wife. Yes, it's the holidays season, so I have to work for her ;-)
Original Post: ISBN-13 to ISBN-10
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.