【散分】怎样用VB把汉字转为URI编码【已解决】

DawnPine 2012-08-22 06:41:14
在URL地址中,一个汉字用 %XX%YY%ZZ 来表示,查了一下,好像这个是叫URI编码
求把汉字转为URI编码的办法。
如果在VBA中调用这个办法,需要引用哪些东西。
谢谢!
...全文
120 点赞 收藏 6
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
DawnPine 2012-08-24
终于来人了
结帖
走人
回复
秋杨 2012-08-24
嗯嗯~结贴吧
回复
宇宙总统 2012-08-24
揭帖把
回复
DawnPine 2012-08-23

Function UTF8EncodeURI(strUTF8 As String) As String
Dim nFor As Long
Dim nAsc As Long
Dim strWchar As String
Dim strURIchar As String

UTF8EncodeURI = ""
For nFor = 1 To Len(strUTF8)
strWchar = Mid(strUTF8, nFor, 1)
nAsc = AscW(strWchar)
If nAsc < 0 Then nAsc = nAsc + 65536
If (nAsc And &HFF80) = 0 Then
UTF8EncodeURI = UTF8EncodeURI & strWchar
ElseIf (nAsc And &HF000) = 0 Then
strURIchar = "%" & Hex(((nAsc \ 2 ^ 6)) Or &HC0) & Hex(nAsc And &H3F Or &H80)
UTF8EncodeURI = UTF8EncodeURI & strURIchar
Else
strURIchar = "%" & Hex((nAsc \ 2 ^ 12) Or &HE0) & _
"%" & Hex((nAsc \ 2 ^ 6) And &H3F Or &H80) & _
"%" & Hex(nAsc And &H3F Or &H80)
UTF8EncodeURI = UTF8EncodeURI & strURIchar
End If
Next
End Function
回复
DawnPine 2012-08-23
居然没人来答。。。。

研究了二年半,终于自己搞定了
Function UTF8EncodeURI(strUTF8 As String) As String
Dim nFor As Long
Dim nAsc As Long
Dim strWchar As String
Dim strURIchar As String

UTF8EncodeURI = ""
For nFor = 1 To Len(strUTF8)
strWchar = Mid(strUTF8, nFor, 1)
nAsc = AscW(strWchar)
If nAsc < 0 Then nAsc = nAsc + 65536
If (nAsc And &HFF80) = 0 Then
UTF8EncodeURI = UTF8EncodeURI & strWchar
ElseIf (nAsc And &HF000) = 0 Then
strURIchar = "%" & Hex(((nAsc \ 2 ^ 6)) Or &HC0) & Hex(nAsc And &H3F Or &H80)
UTF8EncodeURI = UTF8EncodeURI & strURIchar
Else
strURIchar = "%" & Hex((nAsc \ 2 ^ 12) Or &HE0) & _
"%" & Hex((nAsc \ 2 ^ 6) And &H3F Or &H80) & _
"%" & Hex(nAsc And &H3F Or &H80)
UTF8EncodeURI = UTF8EncodeURI & strURIchar
End If
Next
End Function
回复
发动态
发帖子
网络编程
创建于2007-09-28

1469

社区成员

VB 网络编程
申请成为版主
社区公告
暂无公告