URL Encoder and Decoder for VB

Category:
ASP, HTML and XML
Type:
Snippets
Difficulty:
Beginning
Author:
Igor

Version Compatibility:

More information:
These are coder and decoder for URL-coding. The encoded works likes ASP's Server.URLEncode method, except it supports both old and new http standards for substituting space with + or %20. Change UsePlusRatherThanHexForSpace for regulating this.

URL-Encoding scheme is following: Where the local naming scheme uses ASCII characters which are not allowed in the URI (Universal resource Indetifier), these may be represented in the URL by a percent sign "%" immediately followed by two hexadecimal digits (0-9, A-F) giving the ISO Latin 1 code for that character. For example, ampersand (&) is not allowed in URL-coding and should be substituted by it's hex value - %26

Initially, you can use signs like ! in URL-coding - not just alphanumeric (0-9,a-z,A-Z) characters like in this snippet, but here's interception from RFC1630."

'The same encoding method may be used for encoding characters whose use, although technically allowed in a URI, would be unwise due to problems of corruption by imperfect gateways or misrepresentation due to the use of variant character sets, or which would simply be awkward in a given environment. Because a % sign always indicates an encoded character, a URI may be made "safer" simply by encoding any characters considered unsafe, while leaving already encoded characters still encoded. Similarly, in cases where a larger set of characters is acceptable, % signs can be selectively and reversibly expanded.'
Encoder usage: URLEncode("Hello world! :-)") - will return "Hello%20world%21%20%3A%2D%29"

Decoder usage: URLDecode("Hello%20world%21%20%3A%2D%29") - will return "Hello world! :-)"

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: