Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar 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 Private Const CP_UTF8 = 65001 Function Utf8ToUnicode(ByRef Utf() As Byte) As String Dim lRet As Long Dim lLength As Long Dim lBufferSize As Long lLength = UBound(Utf) - LBound(Utf) + 1 If lLength <= 0 Then Exit Function lBufferSize = lLength * 2 Utf8ToUnicode = String$(lBufferSize, Chr(0)) lRet = MultiByteToWideChar(CP_UTF8, 0, VarPtr(Utf(0)), lLength, StrPtr(Utf8ToUnicode), lBufferSize) If lRet <> 0 Then Utf8ToUnicode = Left(Utf8ToUnicode, lRet) End If End FunctionFunction UnicodeToUtf8(ByVal UCS As String) As Byte() Dim lLength As Long Dim lBufferSize As Long Dim lResult As Long Dim abUTF8() As Byte lLength = Len(UCS) If lLength = 0 Then Exit Function lBufferSize = lLength * 3 + 1 ReDim abUTF8(lBufferSize - 1) lResult = WideCharToMultiByte(CP_UTF8, 0, StrPtr(UCS), lLength, abUTF8(0), lBufferSize, vbNullString, 0) If lResult <> 0 Then lResult = lResult - 1 ReDim Preserve abUTF8(lResult) UnicodeToUtf8 = abUTF8 End If End FunctionPrivate Sub Command1_Click() Dim key, s As String Dim i As Integer Text2.Text = "" For i = 1 To Len(Text1.Text) key = Mid(Text1.Text, i, 1) If Asc(key) > &H2F And Asc(key) < &H47 Then s = s & key If Len(s) = 2 And Val("&H" & s) < 127 Then Text2.Text = Text2.Text & Chr(Val("&H" & s)) s = "": key = "" ElseIf Len(s) = 6 Then Text2.Text = Text2.Text & Decode(s) s = "": key = "" End If End If Next End Sub Function Decode(ByVal s As String) As String Dim a() As String, b() As Byte, i As Long ReDim a(3) For z = 0 To 2 a(z) = Mid(s, (z + 1) * 2 - 1, 2) Next z ReDim b(3) For i = 0 To 2 b(i) = CByte("&H" & a(i)) Next Debug.Print b(0) & b(1) & b(2) Decode = Utf8ToUnicode(b) Debug.Print Decode End Function
Option Explicit Dim sj As StringPrivate Sub Command1_Click() Dim sTemp As String Dim yTemp() As Byte Dim i As Integer ReDim yTemp(Len(sj) / 2 - 1) For i = 1 To Len(sj) Step 2 yTemp((i - 1) / 2) = Val("&H" & Mid(sj, i, 2)) Next sTemp = StrConv(yTemp, vbUnicode) Text1 = sTemp End SubPrivate Sub Form_Load() sj = "5345415243487E7E7EE8AFB7E997AEE682A8E683B3E5B9B2E4BB80E4B988EFBC9F" End Sub 'SEARCH~~~璇烽棶鎮ㄦ兂骞蹭粈涔堬紵
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
Private Const CP_UTF8 = 65001
Function Utf8ToUnicode(ByRef Utf() As Byte) As String
Dim lRet As Long
Dim lLength As Long
Dim lBufferSize As Long
lLength = UBound(Utf) - LBound(Utf) + 1
If lLength <= 0 Then Exit Function
lBufferSize = lLength * 2
Utf8ToUnicode = String$(lBufferSize, Chr(0))
lRet = MultiByteToWideChar(CP_UTF8, 0, VarPtr(Utf(0)), lLength, StrPtr(Utf8ToUnicode), lBufferSize)
If lRet <> 0 Then
Utf8ToUnicode = Left(Utf8ToUnicode, lRet)
End If
End FunctionFunction UnicodeToUtf8(ByVal UCS As String) As Byte()
Dim lLength As Long
Dim lBufferSize As Long
Dim lResult As Long
Dim abUTF8() As Byte
lLength = Len(UCS)
If lLength = 0 Then Exit Function
lBufferSize = lLength * 3 + 1
ReDim abUTF8(lBufferSize - 1)
lResult = WideCharToMultiByte(CP_UTF8, 0, StrPtr(UCS), lLength, abUTF8(0), lBufferSize, vbNullString, 0)
If lResult <> 0 Then
lResult = lResult - 1
ReDim Preserve abUTF8(lResult)
UnicodeToUtf8 = abUTF8
End If
End FunctionPrivate Sub Command1_Click()
Dim key, s As String
Dim i As Integer
Text2.Text = ""
For i = 1 To Len(Text1.Text)
key = Mid(Text1.Text, i, 1)
If Asc(key) > &H2F And Asc(key) < &H47 Then
s = s & key
If Len(s) = 2 And Val("&H" & s) < 127 Then
Text2.Text = Text2.Text & Chr(Val("&H" & s))
s = "": key = ""
ElseIf Len(s) = 6 Then
Text2.Text = Text2.Text & Decode(s)
s = "": key = ""
End If
End If
Next
End Sub
Function Decode(ByVal s As String) As String
Dim a() As String, b() As Byte, i As Long
ReDim a(3)
For z = 0 To 2
a(z) = Mid(s, (z + 1) * 2 - 1, 2)
Next z
ReDim b(3)
For i = 0 To 2
b(i) = CByte("&H" & a(i))
Next
Debug.Print b(0) & b(1) & b(2)
Decode = Utf8ToUnicode(b)
Debug.Print Decode
End Function
Dim sj As StringPrivate Sub Command1_Click()
Dim sTemp As String
Dim yTemp() As Byte
Dim i As Integer
ReDim yTemp(Len(sj) / 2 - 1)
For i = 1 To Len(sj) Step 2
yTemp((i - 1) / 2) = Val("&H" & Mid(sj, i, 2))
Next
sTemp = StrConv(yTemp, vbUnicode)
Text1 = sTemp
End SubPrivate Sub Form_Load()
sj = "5345415243487E7E7EE8AFB7E997AEE682A8E683B3E5B9B2E4BB80E4B988EFBC9F"
End Sub
'SEARCH~~~璇烽棶鎮ㄦ兂骞蹭粈涔堬紵