devxlogo

URLPathEncode – Convert a string for using on a URL path

URLPathEncode – Convert a string for using on a URL path

' convert a string so that it can be used on a URL path'' Same effect as the Server.URLPathEncode method in ASPFunction URLPathEncode(ByVal Text As String) As String    Dim i As Integer    Dim acode As Integer        URLPathEncode = Text        For i = Len(URLPathEncode) To 1 Step -1        acode = Asc(Mid$(URLPathEncode, i, 1))        Select Case acode            Case 48 To 57, 65 To 90, 97 To 122                ' don't touch alphanumeric chars            Case 33, 35, 36, 38, 42, 43, 45, 46, 47, 58, 63, 64, 95, 126                ' these punctuation chars require no translation            Case Else                ' replace other chars with "%hex"                URLPathEncode = Left$(URLPathEncode, i - 1) & "%" & Hex$(acode) _                    & Mid$(URLPathEncode, i + 1)        End Select    Next    End Function

devx-admin

Share the Post: