'HEX转汉字
'如H2A("D2BBB6FEC8FDCBC4CEE5")
'返回:一二三四五
Public Function Hex2Ascii(sText As String) As String
If Len(sText) Mod 2 <> 0 Then sText = "0" & sText
Dim arr() As Byte
ReDim arr(Len(sText) 2 - 1) As Byte
Dim xx As Long
For xx = 0 To Len(sText) 2 - 1
arr(xx) = "&h" & Mid(sText, (xx * 2) + 1, 2)
Next
Hex2Ascii = StrConv(arr, vbUnicode)
End Function
'带有汉字的ASCII字符转HEX
'如:Ascii2Hex("一二三四五")
'返回:D2 BB B6 FE C8 FD CB C4 CE E5
Public Function Ascii2Hex(sText As String) As String
Dim i As Long
Dim hzByte() As Byte
hzByte = StrConv(sText, vbFromUnicode)
For i = 0 To UBound(hzByte)
Ascii2Hex = Ascii2Hex & Hex(hzByte(i)) & " "
Next
Ascii2Hex = Trim$(Hz2Hex)
'转回汉字
'Ascii2Hex = StrConv(hzByte, vbUnicode)
End Function
'HEX转汉字
'如H2A("D2BBB6FEC8FDCBC4CEE5")
'返回:一二三四五
Public Function Hex2Ascii(sText As String) As String
If Len(sText) Mod 2 <> 0 Then sText = "0" & sText
Dim arr() As Byte
ReDim arr(Len(sText) 2 - 1) As Byte
Dim xx As Long
For xx = 0 To Len(sText) 2 - 1
arr(xx) = "&h" & Mid(sText, (xx * 2) + 1, 2)
Next
Hex2Ascii = StrConv(arr, vbUnicode)
End Function
'带有汉字的ASCII字符转HEX
'如:Ascii2Hex("一二三四五")
'返回:D2 BB B6 FE C8 FD CB C4 CE E5
Public Function Ascii2Hex(sText As String) As String
Dim i As Long
Dim hzByte() As Byte
hzByte = StrConv(sText, vbFromUnicode)
For i = 0 To UBound(hzByte)
Ascii2Hex = Ascii2Hex & Hex(hzByte(i)) & " "
Next
Ascii2Hex = Trim$(Hz2Hex)
'转回汉字
'Ascii2Hex = StrConv(hzByte, vbUnicode)
End Function
我尝试了 charw() 这个,是可以显示汉字的....
但是这个是只能识别某一种编码还是可以全部识别,就算是某一种编码,当有字符和汉字时,取一个字节还是两个字节怎么选
我发现 现在vb6.0显示汉字用的是unicode码
比如 丁 字,4E01(unicode编码) B6A1(GBK编码)
我用 charw(&H4E01) 可以显示 丁
用 charw(&HB6A1) 时显示的是 ? 号
一周热门 更多>