I have been searching for an AS routine that will properly encode characters such as Ã. All the routines I find turn à into %92, but when I put %92 into the URL and pass it through my browser the receiving site shows me '. Poking around it seems that à should be encoded into %ED.
What routine will encode extended characters like this properly?
This is not really “Url Encode”, but “Form Encode”. As if you were filling a form in a web page. Depending on the page’s encoding, you may encode the text accordingly. Actually, “ED” would be the ISO-Latin-1 (or ISO 8859-1) hex-equivalent to the i-acute. This routine still works:
charToISOLatin1Hex("Ã") --> "ED"
on charToISOLatin1Hex(c)
if (count c) is not 1 then error "Only 1 char at a time, please..."
-- only one character or force error
set c to item -1 of (({{coercionTrick:c as Unicode text}}) as string)
c as C string
try
result * 5
on error msg
return text ((offset of "«data cstr" in msg) + 10) thru ((offset of "00»" in msg) - 1) of msg
end try
end charToISOLatin1Hex