试试: Public Function ascg(smsg As String) As String Dim si, sb As Integer Dim stmp As Integer Dim stemp As String sb = Len(smsg) ascg = "" For si = 1 To sb stmp = AscW(Mid(smsg, si, 1)) If Abs(stmp) < 127 Then stemp = "00" & Hex(stmp) Else stemp = Hex(stmp) End If ascg = ascg & stemp Next si ascg = Trim(ascg) End Function
StrConv 函数的语法为:StrConv(待转换字串, 转换格式) 其中转换格式在这里用到的是: vbUnicode 将 Ansi 字串转换为 Unicode vbFromUnicode 将 Unicode 字串转换为 Ansi Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long 'GetWindowTextA' 指明这是一个非 Unicode API 以下是修改后的 API 声明: Declare Function GetWindowText Lib "user32" Alias "GetWindowTextW" (ByVal hwnd As Long, ByVal lpString As Long, ByVal cch As Long) As Long 'GetWindowTextW' 指明这是一个 Unicode API 由此可见,修改一个非 Unicode API 成为一个 Unicode API 的要点是: * 把 Alias 里函数名的结尾 'A' 换成 'W'。 * 把所有 ByVal *** As String ,改为 ByVal *** As Long 。
function Decode(byval s as string) as string dim a() as string, b() as byte, i as long a = split(trim(s),"%") redim b(ubound(a)) for i=0 to ubound(a) b(i) = cbyte("&H" & a(i)) next Decode = StrConv(b, vbUnicode) end function '== Immediate == ?Decode("%B1%C8%BF%A8%B3%AC") 比卡超
Public Function ascg(smsg As String) As String
Dim si, sb As Integer
Dim stmp As Integer
Dim stemp As String
sb = Len(smsg)
ascg = ""
For si = 1 To sb
stmp = AscW(Mid(smsg, si, 1))
If Abs(stmp) < 127 Then
stemp = "00" & Hex(stmp)
Else
stemp = Hex(stmp)
End If
ascg = ascg & stemp
Next si
ascg = Trim(ascg)
End Function
'GetWindowTextA' 指明这是一个非 Unicode API 以下是修改后的 API 声明: Declare Function GetWindowText Lib "user32" Alias "GetWindowTextW" (ByVal hwnd As Long, ByVal lpString As Long, ByVal cch As Long) As Long
'GetWindowTextW' 指明这是一个 Unicode API 由此可见,修改一个非 Unicode API 成为一个 Unicode API 的要点是:
* 把 Alias 里函数名的结尾 'A' 换成 'W'。
* 把所有 ByVal *** As String ,改为 ByVal *** As Long 。
dim a() as string, b() as byte, i as long
a = split(trim(s),"%")
redim b(ubound(a))
for i=0 to ubound(a)
b(i) = cbyte("&H" & a(i))
next
Decode = StrConv(b, vbUnicode)
end function
'== Immediate ==
?Decode("%B1%C8%BF%A8%B3%AC")
比卡超