如何用EXCEL VBA将汉字转成GB2312的URL编码,如输入"中国",生成"%D6%D0%B9%FA",用于网络查询.
2个回答
展开全部
据说有 MultiByteToWideChar 和 WideCharToMultiByte 这两个函数可以使用,但是我没用过!
写了2个函数,自己改吧!
Public Function uncode(x As Range) As String
On Error Resume Next
MsgBox Asc(Mid(x, 1, 1)) + 65536
If x.Columns.Count <> 1 Then
uncode = "Error"
Exit Function
End If
If Len(x) = 0 Then Exit Function
Dim a, b, c, i
b = ""
For i = 1 To Len(x)
a = Mid(x, i, 1)
If Asc(a) < 0 Then
uncode = uncode & sixteen(Asc(a) + 65536)
Else
uncode = uncode & a
End If
Next
End Function
Public Function sixteen(m As Long) As String
n = m
x = "": y = ""
Do While n <> 0
a = n Mod 2
n = n \ 2
x = a & x
Loop
Do While Len(x) Mod 4 <> 0
x = "0" + x
Loop
Do While Len(x) > 0
Select Case Right(x, 4)
Case "0000"
y = "0" + y
Case "0001"
y = "1" + y
Case "0010"
y = "2" + y
Case "0011"
y = "3" + y
Case "0100"
y = "4" + y
Case "0101"
y = "5" + y
Case "0110"
y = "6" + y
Case "0111"
y = "7" + y
Case "1000"
y = "8" + y
Case "1001"
y = "9" + y
Case "1010"
y = "A" + y
Case "1011"
y = "B" + y
Case "1100"
y = "C" + y
Case "1101"
y = "D" + y
Case "1110"
y = "E" + y
Case "1111"
y = "F" + y
End Select
x = Left(x, Len(x) - 4)
Loop
sixteen = y
End Function
写了2个函数,自己改吧!
Public Function uncode(x As Range) As String
On Error Resume Next
MsgBox Asc(Mid(x, 1, 1)) + 65536
If x.Columns.Count <> 1 Then
uncode = "Error"
Exit Function
End If
If Len(x) = 0 Then Exit Function
Dim a, b, c, i
b = ""
For i = 1 To Len(x)
a = Mid(x, i, 1)
If Asc(a) < 0 Then
uncode = uncode & sixteen(Asc(a) + 65536)
Else
uncode = uncode & a
End If
Next
End Function
Public Function sixteen(m As Long) As String
n = m
x = "": y = ""
Do While n <> 0
a = n Mod 2
n = n \ 2
x = a & x
Loop
Do While Len(x) Mod 4 <> 0
x = "0" + x
Loop
Do While Len(x) > 0
Select Case Right(x, 4)
Case "0000"
y = "0" + y
Case "0001"
y = "1" + y
Case "0010"
y = "2" + y
Case "0011"
y = "3" + y
Case "0100"
y = "4" + y
Case "0101"
y = "5" + y
Case "0110"
y = "6" + y
Case "0111"
y = "7" + y
Case "1000"
y = "8" + y
Case "1001"
y = "9" + y
Case "1010"
y = "A" + y
Case "1011"
y = "B" + y
Case "1100"
y = "C" + y
Case "1101"
y = "D" + y
Case "1110"
y = "E" + y
Case "1111"
y = "F" + y
End Select
x = Left(x, Len(x) - 4)
Loop
sixteen = y
End Function
来自:求助得到的回答
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询