我只写一个简单的,实际的转换,还是比较复杂的,自己慢慢实现,比如某些如"%",":","/"," "等等需要转换,对于基本的Ascii码可以直接使用,下面是一个仅汉字转成UTF8的示例: Private Declare Function WideCharToMultiByte Lib "kernel32" ( _ ByVal CodePage As Long, _ ByVal dwFlags As Long, _ ByVal lpWideCharStr As Long, _ ByVal cchWideChar As Long, _ ByVal lpMultiByteStr As Long, _ ByVal cchMultiByte As Long, _ ByVal lpDefaultChar As Long, _ ByVal lpUsedDefaultChar As Long _ ) As LongDim strUTF8() As Byte, strUTF16 As String Dim lenUTF8 As Long Dim lenUTF16 As Long Dim i As Long Dim strResult As StringstrUTF16 = "冷饮" lenUTF16 = Len(strUTF16)lenUTF8 = lenUTF16 * 3 ReDim strUTF8(lenUTF8)lenUTF8 = WideCharToMultiByte(ByVal 65001, ByVal 0&, ByVal StrPtr(strUTF16), ByVal lenUTF16, ByVal VarPtr(strUTF8(0)), ByVal lenUTF8, ByVal 0&, ByVal 0&) ReDim Preserve strUTF8(lenUTF8 - 1)strResult = "" For i = LBound(strUTF8) To UBound(strUTF8) strResult = strResult & "%" & Hex(strUTF8(i)) NextMsgBox strResult
Private Declare Function WideCharToMultiByte Lib "kernel32" ( _
ByVal CodePage As Long, _
ByVal dwFlags As Long, _
ByVal lpWideCharStr As Long, _
ByVal cchWideChar As Long, _
ByVal lpMultiByteStr As Long, _
ByVal cchMultiByte As Long, _
ByVal lpDefaultChar As Long, _
ByVal lpUsedDefaultChar As Long _
) As LongDim strUTF8() As Byte, strUTF16 As String
Dim lenUTF8 As Long
Dim lenUTF16 As Long
Dim i As Long
Dim strResult As StringstrUTF16 = "冷饮"
lenUTF16 = Len(strUTF16)lenUTF8 = lenUTF16 * 3
ReDim strUTF8(lenUTF8)lenUTF8 = WideCharToMultiByte(ByVal 65001, ByVal 0&, ByVal StrPtr(strUTF16), ByVal lenUTF16, ByVal VarPtr(strUTF8(0)), ByVal lenUTF8, ByVal 0&, ByVal 0&)
ReDim Preserve strUTF8(lenUTF8 - 1)strResult = ""
For i = LBound(strUTF8) To UBound(strUTF8)
strResult = strResult & "%" & Hex(strUTF8(i))
NextMsgBox strResult