zoukankan      html  css  js  c++  java
  • 生成字符串校验码的方法

             以前的一个项目中遇到过要核对条码的校验码的需求,感觉有时候还是非常有用的,下面提供代码,代码版本为VB.net:

     //根据输入的的条码来计算该条码的校验位

    Private Function GetCheckDigit(Byal strCode As String) As String
            Dim intCurVal As Int16 = 0
            Dim intChksum As Int16 = 0
            Dim chrCur As String
            Dim intPos As Int16
            'Check for invalid characters and calculate check sum
            For intPos = 1 To Len(strCode)
                chrCur = Mid(strCode, intPos, 1)
                Select Case chrCur
                    Case "0" To "9"
                        intCurVal = Val(chrCur)
                    Case "A" To "Z"
                        intCurVal = Asc(chrCur) - 55
                    Case "-"
                        intCurVal = 36
                    Case "."
                        intCurVal = 37
                    Case " "
                        intCurVal = 38
                    Case "$"
                        intCurVal = 39
                    Case "/"
                        intCurVal = 40
                    Case "+"
                        intCurVal = 41
                    Case "%"
                        intCurVal = 42
                    Case Else
                End Select
                intChksum = intChksum + intCurVal
            Next
            intChksum = intChksum Mod 43
            Select Case intChksum
                Case 0 To 9
                    Return intChksum.ToString()
                Case 10 To 35
                    Return Chr(intChksum + 55)
                Case 36
                    Return "-"
                Case 37
                    Return "."
                Case 38
                    Return " "
                Case 39
                    Return "$"
                Case 40
                    Return "/"
                Case 41
                    Return "+"
                Case 42
                    Return "%"
                Case Else
            End Select
            Return "0"
        End Function
     
  • 相关阅读:
    Linux常用命令
    IDEA神器
    Nginx配置文件变量大全
    php-fpm.conf 文件详解
    mysqlsla慢查询分析工具教程
    Nginx upstream的5种权重分配方式
    Nginx简单性能调优
    MySQL 5.5主从同步设置教程
    mongoDB中批量修改字段
    Python学习笔记第四周
  • 原文地址:https://www.cnblogs.com/kevinGao/p/2192735.html
Copyright © 2011-2022 走看看