Thank you!问题已解决。Private Sub Command1_Click() Dim s As String s = String2Hex("今天abc123") MsgBox s s = Hex2String(s) MsgBox s End SubPrivate Function String2Hex(ByVal s As String) As String On Error Resume Next Dim bytearr() As Byte bytearr = StrConv(s, vbFromUnicode) Dim temps As String Dim temp As Byte Dim i As Long Dim outs As String For i = 0 To UBound(bytearr) temp = bytearr(i) temps = Hex(temp) temps = Right("00" + temps, 2) outs = outs + temps Next String2Hex = outs End Function Private Function Hex2String(ByVal s As String) As String On Error Resume Next Dim bytearr() As Byte Dim temps As String Dim temp As Byte Dim i As Long Dim j As Long j = 0 Dim outs As String For i = 1 To Len(s) Step 2 temps = Mid(s, i, 2) temp = Val("&H" & temps) ReDim Preserve bytearr(j) bytearr(j) = temp j = j + 1 Next outs = StrConv(bytearr, vbUnicode) Hex2String = outs End Function
罗
Dim s As String
s = String2Hex("今天abc123")
MsgBox s
s = Hex2String(s)
MsgBox s
End SubPrivate Function String2Hex(ByVal s As String) As String
On Error Resume Next
Dim bytearr() As Byte
bytearr = StrConv(s, vbFromUnicode)
Dim temps As String
Dim temp As Byte
Dim i As Long
Dim outs As String
For i = 0 To UBound(bytearr)
temp = bytearr(i)
temps = Hex(temp)
temps = Right("00" + temps, 2)
outs = outs + temps
Next
String2Hex = outs
End Function
Private Function Hex2String(ByVal s As String) As String
On Error Resume Next
Dim bytearr() As Byte
Dim temps As String
Dim temp As Byte
Dim i As Long
Dim j As Long
j = 0
Dim outs As String
For i = 1 To Len(s) Step 2
temps = Mid(s, i, 2)
temp = Val("&H" & temps)
ReDim Preserve bytearr(j)
bytearr(j) = temp
j = j + 1
Next
outs = StrConv(bytearr, vbUnicode)
Hex2String = outs
End Function