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  

  • 相关阅读:
    html5数字和颜色输入框
    WinForm设置右键菜单
    设置窗体透明C#代码
    C#调用windows api示例
    使用VS GDB扩充套件在VS上远端侦错Linux上的C/C++程序
    javascript系统时间测试题
    博客园学习的好地方
    基于jQuery的自适应图片左右切换
    HTML+CSS代码橙色导航菜单
    ASP.NET使用UpdatePanel实现AJAX
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668512.html
Copyright © 2011-2022 走看看