URL DECODE Function

Modified on 2016/12/17 19:52 by CaptainBoing — Categorized as: Encode and Decode, Network, Strings

Decodes the query part of a URL string. URL encoding is used when placing text in a query string to avoid it being confused with the URL itself. It is normally used when the browser sends form data to a web server as part of the URI - as part of the "web address" (GET method).

Syntax:
URLDecode$(expression)

Example:
realURL$=URLDecode$(RecdURL)

Code:
  FUNCTION URLDecode$(a$)
    LOCAL INTEGER z
    LOCAL STRING b$,c$
    z=1
    DO
      z=INSTR(z,a$,"%")
      IF z=0 OR z=LEN(a$) THEN EXIT DO
        b$=MID$(a$,z,3)
        c$=CHR$(VAL("&h"+MID$(b$,2)))
        a$=Replace$(a$,b$,c$)
      END IF
    LOOP
    URLDecode$=a$
  END FUNCTION