Raised This Month: $51 Target: $400
 12% 

Decode URI encoded string


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode