VB 字符串十六进制组加1的算法

今碰到个需要对16进制的字符串进行加1的需求,写了以下函数。

Private Function AddHexString(s As String) As String

 

    ReDim n(Len(s))

 

    For i = 0 To UBound(n) - 1

        n(i) = Asc(Mid(s, Len(s) - i, 1))

    Next

   

    If ((n(0)) >= 48 And (n(0)) < 57) Or ((n(0)) >= 65 And (n(0)) < 70) Then

        n(0) = n(0) + 1

    ElseIf n(0) = 57 Then

        n(0) = 65

       

    ElseIf (n(0)) = 70 Then

 

        Dim z As Integer

 

        z = 0

 

        Do While (n(z) = 70)

            n(z) = 48

            z = z + 1

 

            If z > UBound(n) Then Exit Do

           

            If ((n(z)) >= 48 And (n(z)) < 57) Or ((n(z)) >= 65 And (n(z)) < 70) Then

                n(z) = n(z) + 1

                If n(z) = 70 Then Exit Do

            ElseIf n(z) = 57 Then

                n(z) = 65

            End If

 

        Loop

       

    End If

 

    For i = UBound(n) To 0 Step -1

 

        If n(i) > 0 Then

            AddString = AddString & Chr(n(i))

        End If

 

    Next

 

End Function

 

posted @ 2015-04-20 09:50  龙爷  阅读(710)  评论(0编辑  收藏  举报