首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >生成.NET EAN-13字符串

生成.NET EAN-13字符串
EN

Stack Overflow用户
提问于 2018-02-16 13:20:02
回答 1查看 2.5K关注 0票数 1

有人能推荐一个(免费的商业使用)库来生成EAN-13条形码吗?

我不需要图像,只需要字符串。

我想传递产品代码,制造商代码和国家/地区(不是数字系统)作为参数。

它可以将国家/地区转换为数字系统,并将其连接在一起计算校验和。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-16 22:04:05

基本上:Ean13是一个基于模型的校验和计算:

因此,您有一个12位数字,没有校验和,然后添加校验和。

CheckSum函数:

代码语言:javascript
复制
   public static string CalculateEan13(string country, string manufacturer, string product)
    {
        string temp = $"{country}{manufacturer}{product}";
        int sum = 0;
        int digit = 0;

        // Calculate the checksum digit here.
        for (int i = temp.Length; i >= 1; i--)
        {
            digit = Convert.ToInt32(temp.Substring(i - 1, 1));
            // This appears to be backwards but the 
            // EAN-13 checksum must be calculated
            // this way to be compatible with UPC-A.
            if (i % 2 == 0)
            { // odd  
                sum += digit * 3;
            }
            else
            { // even
                sum += digit * 1;
            }
        }
        int checkSum = (10 - (sum % 10)) % 10;
        return $"{temp}{checkSum}";
    }

如何自己计算您的支票数字

示例条形码号码: 501234576421

步骤1:将所有从右边开始的备用数字相加在一起

5 0 1 2 3 4 5 7 6 2 1

0+2+4+7+4+1= 18

第二步:将答案乘以3

18x3= 54

第3步:现在将剩余的数字相加

5 0 1 2 3 4 5 7 6 2 1

5+1+3+5+6+2= 22

步骤4:将步骤2和步骤3相加在一起

54 + 22 = 76

第5步:第4步与下一个第10步的区别:

76 +4= 80

检查数字=4

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48827715

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档