zoukankan      html  css  js  c++  java
  • VB 936(gb2312)URL编码与解码

    Private Sub Command1_Click()
    Text2.Text = URLEncode(Text1.Text)
    End Sub


    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

    Private Sub Command2_Click()
    Text3.Text = URLDecode(Text2.Text)
    End Sub

    Private Sub Form_Load()
    Text1.Text = "微迈互联"
    End Sub  

  • 相关阅读:
    互斥锁的通俗理解
    U-Boot下分区信息查看
    《计算机组成原理》唐朔飞第二版_笔记
    《大话程序员》安晓辉_笔记
    C++ 类对象的初始化顺序
    FilterTerminal使用说明全总结
    sed -i 命令常用方法总结
    入园记录
    cookies,sessionStorage 和 localStorage区别
    优雅降级和渐进增强的理解:
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668512.html
Copyright © 2011-2022 走看看