Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

URL Encoding and Decoding of Special Characters


  • Please log in to reply
19 replies to this topic
  • Guests
  • Last active:
  • Joined: --
uri-encoding requires the string be encoded as UTF-8 first. E.g: '£' -> '£'. Once you do that, converting unreserved characters to %XX format is trivial.

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
I found a function on the forum now that does exactly that and encodes all non-alphanumeric chars.

  • Guests
  • Last active:
  • Joined: --
If you have access to the Uri type you can just do Uri.UnescapeDataString().

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
Do you mean in a script control? The issue is that this is not available on x64.

AHKTeo14
  • Members
  • 9 posts
  • Last active: Jul 16 2018 09:32 PM
  • Joined: 09 Apr 2014
Sorry folks,
this is an old one, but i fiddling around with an Google Maps Viewer in AHK,
and i got strange Problem with Umlauts.
I need to translate "%C3%96sterreich" into "Österreich"

#NoEnv

;works fine
str:=uriDecode("d%C3%A4nemark")
MsgBox % str "`r" fnUTF8ToANSI(str)

;never works
str:=uriDecode("#q=%C3%96sterreich")
MsgBox % str "`r" fnUTF8ToANSI(str)

ExitApp

uriDecode(str)
{
; Find uri encoded characters such as %20 (space) and replace with ascii character

pos = 1
Loop
If pos := RegExMatch(str, "i)(?<=%)[\da-f]{2}", hex, pos++)
StringReplace, str, str, `%%hex%, % Chr("0x" . hex), All
Else Break
Return, str
}

;Convert UTF8 to ANSI
fnUTF8ToANSI(sUTFString)
{
;--> static ANSI:="cp1252", UTF8:="cp65001"
static ANSI:="cp0", UTF8:="cp65001"
iLen:=StrPut(sUTFString,ANSI)
VarSetCapacity(vConvert,iLen)
StrPut(sUTFString,&vConvert,iLen,ANSI)
sResult:=StrGet(&vConvert,UTF8)
return % sResult
}