Public Function Strcode2(StringX As String) As String
Dim i As Long
Dim j As Long
Dim sByte() As Byte
For i = 0 To Len(Trim(StringX)) - 1
If (Asc(Mid(StringX, i + 1, 1)) >= Asc("0") And Asc(Mid(StringX, i + 1, 1)) <= Asc("9")) Or (Asc(Mid(StringX, i + 1, 1)) >= Asc("@") And Asc(Mid(StringX, i + 1, 1)) <= Asc("Z")) Or (Asc(Mid(StringX, i + 1, 1)) >= Asc("a") And Asc(Mid(StringX, i + 1, 1)) <= Asc("z")) Then
Strcode2 = Strcode2 & Mid(StringX, i + 1, 1)
Else
sByte = StrConv(Mid(StringX, i + 1, 1), vbFromUnicode)
For j = LBound(sByte) To UBound(sByte)
Strcode2 = Strcode2 & Hex(sByte(j))
Next j
End If
Next i
End Function
Private Function Strcode1(str As String) As String
Dim sByte(1) As Byte
sByte(0) = Val("&H" & Mid(str, 1, 2))
sByte(1) = Val("&H" & Mid(str, 3, 2))
Strcode1 = StrConv(sByte, vbUnicode)
End Function
Private Sub Form_Load()
Dim aa As String
aa = "中"
MsgBox aa & " 对应的十六进制编码为: " & Strcode2(aa)
aa = Strcode2(aa) '这是一个十六进制的编码
MsgBox aa & " 对应的中文为: " & Strcode1(aa)