View Single Post
DotNetJunkie
Senior Member
Join Date: May 2005
Location: In front of my pc
Old 10-21-2006 , 13:58   Re: Decode URI encoded string
Reply With Quote #3

Link wasn't intended to be a valid link. I placed "e.g." next to it which stands
for Example Given. A URI encoded string is usually used by the HTTP protocol
to use special characters which are not permitted by the protocol.

Say we have the space character which in hexadecimal is represented by 20
and is 32 in decimal ASCII however a HTTP request looks like this:

GET /some file.txt HTTP/1.1

as we can see the server needs to parse this message and obviously we
cannot use a space because it would screw up the parsing since the server
will be using a space as the delimiter so in order to access a filename with a
space on the server we would encode the URI to look like this:

GET /some%20file.txt HTTP/1.1

Now the server can correctly parse the request without any problems however
now it needs to decode the URI encoded string, in order to do this the server
examines the string until it finds a '%' character meaning that we've reached
an encoded character so the server grabs the next two characters and converts
the given hexadecimal number, which in this example is 20, and converts it to
an ASCII character which is 32.

This function would take a string that looks like:
%48ello%2DWorld%21
and convert it to its unencoded form:
Hello-World!

Unfortunately I have not written an encoding function yet but hopefully you
get the idea.

But overall URI encoded strings are usually used to make what would be
over-complicated parsing into a simple one.
__________________

Last edited by DotNetJunkie; 10-21-2006 at 14:01.
DotNetJunkie is offline
Send a message via ICQ to DotNetJunkie Send a message via AIM to DotNetJunkie Send a message via MSN to DotNetJunkie Send a message via Yahoo to DotNetJunkie