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

This is used to decode a URI encoded string like you often see in
web browsers e.g. http://someplace.com/some%20file.txt

I needed this for a project and didn't know of any function that could do it.

You'll need the HexToDec function found here:
http://forums.alliedmods.net/showthread.php?t=46216

Code:
public decodeURI(string[])
{
	new len = strlen(string);
	if( len <= 0 ) return 0;
	new temp[512];
	new hexstr[3] = { '0' , '0' , 0 };
	new pos = 0;
	new tpos = 0;
	while( pos < len && tpos < sizeof(temp) )
	{
		if( string[pos] == '%' )
		{
			hexstr[0] = string[pos+1];
			hexstr[1] = string[pos+2];
			pos += 3;
			temp[tpos] = HexToDec(hexstr);
			tpos++;
			continue;	
		}
		temp[tpos] = string[pos];
		pos++;
		tpos++;
	}
	setc(string,len,0);
	copy(string,len,temp);
	return 1;
}
__________________
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