Access如何将二进制UTF8转成字符串
时间:2013-07-22 14:32 来源:Office中国 作者:tmtony 阅读:次
分享一个utf-8转字符串的函数。解决编码带来的错误!
调用方法:
Private Sub cmdConvert_Click()
fm20TxtText.Text = FromUtf8(FromHex(fm20TxtHex.Text))
End Sub
函数如下:
Private Declare Function CryptStringToBinary Lib "Crypt32" _
Alias "CryptStringToBinaryW" ( _
ByVal pszString As Long, _
ByVal cchString As Long, _
ByVal dwFlags As Long, _
ByVal pbBinary As Long, _
ByRef pcbBinary As Long, _
ByRef pdwSkip As Long, _
ByRef pdwFlags As Long) As Long
Private Declare Function MultiByteToWideChar Lib "kernel32" ( _
ByVal CodePage As Long, _
ByVal dwFlags As Long, _
ByVal lpMultiByteStr As Long, _
ByVal cchMultiByte As Long, _
ByVal lpWideCharStr As Long, _
ByVal cchWideChar As Long) As Long
Public Function FromHex(ByRef HexString As String) As Byte()
Const CRYPT_STRING_HEX As Long = &H4&
Dim lngOutLen As Long
Dim dwActualUsed As Long
Dim bytBinary() As Byte
If Len(HexString) < 1 Then Exit Function
'Determine output buffer length required.
If CryptStringToBinary(StrPtr(HexString), _
Len(HexString), _
CRYPT_STRING_HEX, _
0&, _
lngOutLen, _
ByVal 0&, _
dwActualUsed) = 0 Then
Err.Raise &H80044100, "FromHex", _
"CryptStringToBinary failed, error " & CStr(Err.LastDllError)
Else
'Convert to binary.
ReDim bytBinary(lngOutLen - 1)
If CryptStringToBinary(StrPtr(HexString), _
Len(HexString), _
CRYPT_STRING_HEX, _
VarPtr(bytBinary(0)), _
lngOutLen, _
调用方法:
Private Sub cmdConvert_Click()
fm20TxtText.Text = FromUtf8(FromHex(fm20TxtHex.Text))
End Sub
函数如下:
Private Declare Function CryptStringToBinary Lib "Crypt32" _
Alias "CryptStringToBinaryW" ( _
ByVal pszString As Long, _
ByVal cchString As Long, _
ByVal dwFlags As Long, _
ByVal pbBinary As Long, _
ByRef pcbBinary As Long, _
ByRef pdwSkip As Long, _
ByRef pdwFlags As Long) As Long
Private Declare Function MultiByteToWideChar Lib "kernel32" ( _
ByVal CodePage As Long, _
ByVal dwFlags As Long, _
ByVal lpMultiByteStr As Long, _
ByVal cchMultiByte As Long, _
ByVal lpWideCharStr As Long, _
ByVal cchWideChar As Long) As Long
Public Function FromHex(ByRef HexString As String) As Byte()
Const CRYPT_STRING_HEX As Long = &H4&
Dim lngOutLen As Long
Dim dwActualUsed As Long
Dim bytBinary() As Byte
If Len(HexString) < 1 Then Exit Function
'Determine output buffer length required.
If CryptStringToBinary(StrPtr(HexString), _
Len(HexString), _
CRYPT_STRING_HEX, _
0&, _
lngOutLen, _
ByVal 0&, _
dwActualUsed) = 0 Then
Err.Raise &H80044100, "FromHex", _
"CryptStringToBinary failed, error " & CStr(Err.LastDllError)
Else
'Convert to binary.
ReDim bytBinary(lngOutLen - 1)
If CryptStringToBinary(StrPtr(HexString), _
Len(HexString), _
CRYPT_STRING_HEX, _
VarPtr(bytBinary(0)), _
lngOutLen, _
(责任编辑:admin)
顶一下
(1)
100%
踩一下
(0)
0%
相关内容
- ·关于 Partition 函数在分组查询中的应
- ·Access算术运算符的含义和说明表
- ·mid函数的另类用法
- ·access制作程序运行进度框
- ·Function与Sub的异同(函数调用)
- ·Access判断某个数值是否为某个数据类型
- ·select case后面语句块的值的四种格式
- ·vba条件语句的两种表示方法
- ·Access几种数据类型初始化的值
- ·Access vba null与""空字符串的区别
- ·access vba 数据类型表
- ·Access变量的命名规则
- ·Access中EXIT Sub与End Sub的区别
- ·Access vba中参数前关键字ByRef和ByVal
- ·Access列表框快速全选的技巧【最快】
- ·vba函数的数据类型强制转换
最新内容
推荐内容