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

DawnPine 2012-08-22 06:41:14
在URL地址中,一个汉字用 %XX%YY%ZZ 来表示,查了一下,好像这个是叫URI编码
求把汉字转为URI编码的办法。
如果在VBA中调用这个办法,需要引用哪些东西。
谢谢!
...全文
333 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
DawnPine 2012-08-24
  • 打赏
  • 举报
回复
终于来人了
结帖
走人
秋杨 2012-08-24
  • 打赏
  • 举报
回复
嗯嗯~结贴吧
net_friends 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

1,502

社区成员

发帖
与我相关
我的任务
社区描述
VB 网络编程
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧