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  

  • 相关阅读:
    linux常见的编码转换
    linux sort的用法
    转--11个失败之后
    shell入门
    迟到
    必须要回答的问题
    【转载】个人开发者要掌握的时间规划建议
    Unity 碰撞检测 OnTriggerEnter 入门
    浅谈BUFF设计
    随机掉宝,对玩家来讲真的随机吗?
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668512.html
Copyright © 2011-2022 走看看