หน้าเว็บ

วันศุกร์ที่ 12 สิงหาคม พ.ศ. 2554

URLEncode / URLDecode [ VB6 ]


Public Function URLdecshort(ByRef Text As String) As String
    Dim strArray() As String, lngA As Long
    strArray = Split(Replace(Text, "+", " "), "%")
    For lngA = 1 To UBound(strArray)
        strArray(lngA) = Chr$("&H" & Left$(strArray(lngA), 2)) & Mid$(strArray(lngA), 3)
    Next lngA
    URLdecshort = Join(strArray, vbNullString)
End Function
Public Function URLencshort(ByRef Text As String) As String
    Dim lngA As Long, strChar As String
    For lngA = 1 To Len(Text)
        strChar = Mid$(Text, lngA, 1)
        If strChar Like "[A-Za-z0-9]" Then
        ElseIf strChar = " " Then
            strChar = "+"
        Else
            strChar = "%" & Right$("0" & Hex$(Asc(strChar)), 2)
        End If
        URLencshort = URLencshort & strChar
    Next lngA
End Function
# Using #
Private Sub Command1_Click()
Text2.Text = URLencshort(Text1.Text)
End Sub

Ref : http://www.vbforums.com/showthread.php?t=541683

ไม่มีความคิดเห็น:

แสดงความคิดเห็น