[Gambas-user] URL encoding "%20"

Rob sourceforge-raindog2 at ...94...
Tue Dec 30 21:23:11 CET 2008


On Tuesday 30 December 2008 08:03, werner 007 wrote:
> Ok, i got the answer by my self.
> The chars of not printable and non-ascii are represented as Hex.
> To convert it back:

That'll work, but it'll also run Replace() 160 times each time you do a 
conversion.  I'd do something like this:

function urlencode(strin as string) as string
	dim strout as string
	dim i as integer
	dim a as integer
	for i = 1 to len(strin)
	        a = asc(mid(strin, i, 1))
	        if a < 33 or a > 126 then
	           strout = strout & "%" & Hex$(a, 2)
	        else
	           strout = strout & mid(strin, i, 1)
	        endif
	next
	return strout
end

Rob




More information about the User mailing list