Click here to Skip to main content
15,897,187 members
Articles / Programming Languages / C#
Tip/Trick

Convert ISBN10 To ISBN 13

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
27 Apr 2010CPOL 16.9K   2  
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)


Written By
Web Developer
Iran (Islamic Republic of) Iran (Islamic Republic of)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --