• 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  

  • 相关阅读:
    ov5640调试过程
    关于OnPaint函数的工作原理(很详细,很实用) [转载]
    机器视觉网络资源
    (转)signaltap II数据用于仿真
    DataSocket简介
    datasocket使用网络传输图像
    共享变量/全局变量/datasocket
    [转载] 任意频率分频原理
    [转]影响FPGA设计中时钟因素的探讨
    生产者和消费者
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668512.html
Copyright © 2020-2023  润新知