永发信息网

网页的url编码怎么用vb来实现?

答案:2  悬赏:20  手机版
解决时间 2021-04-05 04:05
比如百度,出来的结果是%B0%D9%B6%C8,怎么用vb代码实现
最佳答案
我发你编码和解码的vb实现代码:
Private Function URLEncode(ByVal strURL As String) As String
    Dim i As Long
    Dim tempStr As String
    For i = 1 To Len(strURL)
        If InStr("-,.0123456789", Mid(strURL, i, 1)) Then
            URLEncode = URLEncode & Mid(strURL, i, 1)
        Else
            If Asc(Mid(strURL, i, 1)) < 0 Then
                tempStr = "%" & Right(CStr(Hex(Asc(Mid(strURL, i, 1)))), 2)
                tempStr = "%" & Left(CStr(Hex(Asc(Mid(strURL, i, 1)))), Len(CStr(Hex(Asc(Mid(strURL, i, 1))))) - 2) & tempStr
                URLEncode = URLEncode & tempStr
            ElseIf (Asc(Mid(strURL, i, 1)) >= 65 And Asc(Mid(strURL, i, 1)) <= 90) Or (Asc(Mid(strURL, i, 1)) >= 97 And Asc(Mid(strURL, i, 1)) <= 122) Then
                URLEncode = URLEncode & Mid(strURL, i, 1)
            Else
                URLEncode = URLEncode & "%" & Hex(Asc(Mid(strURL, i, 1)))
            End If
        End If
    Next
End Function

Public Function URLDecode(strURL)
    Dim I
    If InStr(strURL, "%") = 0 Then URLDecode = strURL: Exit Function
    For I = 1 To Len(strURL)
        If Mid(strURL, I, 1) = "%" Then
            If eval("&H" & Mid(strURL, I + 1, 2)) > 127 Then
                URLDecode = URLDecode & Chr(eval("&H" & Mid(strURL, I + 1, 2) & Mid(strURL, I + 4, 2)))
                I = I + 5
            Else
                URLDecode = URLDecode & Chr(eval("&H" & Mid(strURL, I + 1, 2)))
                I = I + 2
            End If
        Else
            URLDecode = URLDecode & Mid(strURL, I, 1)
        End If
    Next
End Function
全部回答
'编码函数 public function urlencode(byref strurl as string) as string  dim i as long  dim tempstr as string  for i = 1 to len(strurl)  if asc(mid(strurl, i, 1)) < 0 then  tempstr = "%" & right(cstr(hex(asc(mid(strurl, i, 1)))), 2)  tempstr = "%" & left(cstr(hex(asc(mid(strurl, i, 1)))), len(cstr(hex(asc(mid(strurl, i, 1))))) - 2) & tempstr  urlencode = urlencode & tempstr  elseif  (asc(mid(strurl, i, 1)) >= 65 and asc(mid(strurl, i, 1)) <= 90)  or (asc(mid(strurl, i, 1)) >= 97 and asc(mid(strurl, i, 1)) <=  122) then  urlencode = urlencode & mid(strurl, i, 1)  else  urlencode = urlencode & "%" & hex(asc(mid(strurl, i, 1)))  end if  next  end function  '解码函数 public function urldecode(byref strurl as string) as string  dim i as long  if instr(strurl, "%") = 0 then urldecode = strurl: exit function  for i = 1 to len(strurl)  if mid(strurl, i, 1) = "%" then  if val("&h" & mid(strurl, i + 1, 2)) > 127 then  urldecode = urldecode & chr(val("&h" & mid(strurl, i + 1, 2) & mid(strurl, i + 4, 2)))  i = i + 5  else  urldecode = urldecode & chr(val("&h" & mid(strurl, i + 1, 2)))  i = i + 2  end if  else  urldecode = urldecode & mid(strurl, i, 1)  end if  next  end function
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
为什么北方女的比南方的漂亮,容易嫁入豪门
打90平米的楼板10个厚度需要纱子水泥石头子个
单选题Then she wanted to r
钱到用时方恨少 什么意思?
意境很美的古诗词
战神4技能应该怎么学
什么叫职业目标和职业规划是一个意思吗?
怎样报考福建书法等级考试
全新迈腾将20万开卖 哪些竞争对手会惶惶不安
大连惠德食品有限公司在哪里啊,我有事要去这
如图折叠矩形的边AD,点D落在BC边的F点处,已
完形填空It was one of the hottest days of
健自然医学养身馆地址有知道的么?有点事想过
做人要有尊严的名言,既不伤人自尊心有幽默的
培训什么内容
推荐资讯
吃了汤臣倍健左旋肉碱茶多酚荷叶片后都有哪些
一副三角板如图所示放置,直角顶点重合,斜边
夺目的什么什么?
报恩父母的句子社会向,向父母认错的检讨书
求歌名,有一句歌词是:我愿化做一朵一朵白云漂
华为手机怎么更改存储位置
在微波炉怎么热牛奶,怎么热牛奶比较好?
青岛到巴谚淖尔火车票价
2020年初中全部进城,是不是真的?
履约依据是什么,履约二次是什么意思
日昀存款和月底冲量是什么意思??
正方形OABC以定点o旋转得到正方形ODEF,你能推
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?