VB中的GBK编码

前端之家收集整理的这篇文章主要介绍了VB中的GBK编码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Option Explicit
Function FormatNameToMac(val As String) As String
    Dim i   As Integer
    Dim str As String
    str = ""

    For i = 1 To Len(val)

        If CLng("&h" & Hex(Asc(Mid(val,i,1)))) < 127 Then
            str = str & NumToStrHex(Asc(Mid(val,1)),1)
        Else
            str = str & NumToStrHex(Asc(Mid(val,2)
        End If
    Next
    For i = 1 To Len(str) Step 2
        FormatNameToMac = FormatNameToMac & "%" & Mid$(str,2)
    Next
    'FormatNameToMac = ""
    'For i = 1 To Len(str) Step 4

        'If Len(Mid(str,4)) = 4 Then
        '    FormatNameToMac = FormatNameToMac & H_To_L(Mid(str,4))
        'Else
        '    FormatNameToMac = FormatNameToMac & Mid(str,4)
        'End If
    'Next
End Function

Function NumToStrHex(ByVal num As Long,ByVal bytLen As Integer) As String
  Dim str As String
  Dim strReturn As String
  Dim i As Integer
  Dim iLen As Integer
  str = CStr(Hex(num))
  iLen = bytLen * 2
  strReturn = ""
  If Len(str) >= iLen Then
  strReturn = Right(str,iLen)
  Else
  For i = Len(str) To iLen - 1
  strReturn = strReturn & "0"
  Next
  strReturn = strReturn & str
  End If
  NumToStrHex = strReturn
End Function

Function H_To_L(val As String) As String
  H_To_L = Right(val,2) & Left(val,2)
End Function
原文链接:https://www.f2er.com/vb/259558.html

猜你在找的VB相关文章