Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Convert ISBN10 To ISBN 13

5.00/5 (1 vote)
27 Apr 2010CPOL 1  
Below function get ISBN10 parameter and return ISBN13 :public string GetISBN13(string ISBN) { string isbn10 = 978 + ISBN.Substring(0, 9); int isbn10_1 = Convert.ToInt32(isbn10.Substring(0, 1)); int isbn10_2 =...
Below function get ISBN10 parameter and return ISBN13 :

C#
public string GetISBN13(string ISBN)
        {
            string isbn10 = "978" + ISBN.Substring(0, 9);
            int isbn10_1 = Convert.ToInt32(isbn10.Substring(0, 1));
            int isbn10_2 = Convert.ToInt32(Convert.ToInt32(isbn10.Substring(1, 1)) * 3);
            int isbn10_3 = Convert.ToInt32(isbn10.Substring(2, 1));
            int isbn10_4 = Convert.ToInt32(Convert.ToInt32(isbn10.Substring(3, 1)) * 3);
            int isbn10_5 = Convert.ToInt32(isbn10.Substring(4, 1));
            int isbn10_6 = Convert.ToInt32(Convert.ToInt32(isbn10.Substring(5, 1)) * 3);
            int isbn10_7 = Convert.ToInt32(isbn10.Substring(6, 1));
            int isbn10_8 = Convert.ToInt32(Convert.ToInt32(isbn10.Substring(7, 1)) * 3);
            int isbn10_9 = Convert.ToInt32(isbn10.Substring(8, 1));
            int isbn10_10 = Convert.ToInt32(Convert.ToInt32(isbn10.Substring(9, 1)) * 3);
            int isbn10_11 = Convert.ToInt32(isbn10.Substring(10, 1));
            int isbn10_12 = Convert.ToInt32(Convert.ToInt32(isbn10.Substring(11, 1)) * 3);
            int k = (isbn10_1 + isbn10_2 + isbn10_3 + isbn10_4 + isbn10_5 + isbn10_6 + isbn10_7 + isbn10_8 + isbn10_9 + isbn10_10 + isbn10_11 + isbn10_12);
            int checkdigit = 10 - ((isbn10_1 + isbn10_2 + isbn10_3 + isbn10_4 + isbn10_5 + isbn10_6 + isbn10_7 + isbn10_8 + isbn10_9 + isbn10_10 + isbn10_11 + isbn10_12) % 10);
            if (checkdigit == 10)
                checkdigit = 0;
            return isbn10 + checkdigit.ToString();
        }

Enjoy it

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)