UTF8 Help

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
stoneferry
Posts: 1
Joined: 02 Apr 2018, 12:55

UTF8 Help

18 Apr 2018, 15:18

Hi ,

I've seen a ton of other posts about Autohotkey and UTF8 and nothing has helped so far.

I'm pulling out UTF8 characters out of a JSON file and have a choice of both the UTF8 literal and hex codemap variants:
\xc3\xa9
\u00e9
character = é

I'm looking for a way in Autohotkey to convert the strings with these Unicode hex to their actual equivalent for standard output.

At the moment I'm not concerned with saving output format since I cannot even get standard output working, i.e. Send, command or MsgBox,

The only standard output I ever get is \xc3\xa9

Does anyone have any code to convert a string, i.e. "Saut\xc3\xa9" to "Sauté" ?

Can anybody assist?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: UTF8 Help

04 Jun 2018, 00:22

- This link might be helpful:
unicode escaped string convert (\u00..) - Ask for Help - AutoHotkey Community
https://autohotkey.com/board/topic/6326 ... nvert-u00/
- Btw does anyone know of any standard name for \u0000 etc? I tried looking in the past, but couldn't find one.
- Here are outlines of the basic principles for handling the 2 strings. Handling the \u style should be easier than handling the \x style.

Code: Select all

;handle \u
vText := "Saut\u00e9"
MsgBox, % StrReplace(vText, "\u00e9", Chr(0x00e9))

;handle \x method 1
VarSetCapacity(vData, 255, 0)
Loop, 255
	NumPut(A_Index, &vData, A_Index-1, "UChar")
oChar := StrSplit(StrGet(&vData, 255, "CP0"))
vText := "Saut\xc3\xa9"
vText := StrReplace(vText, "\xc3", oChar[0xc3])
vText := StrReplace(vText, "\xa9", oChar[0xa9])
MsgBox, % vText
VarSetCapacity(vData, StrLen(vText))
StrPut(vText, &vData, StrLen(vText), "CP0")
MsgBox, % StrGet(&vData, StrLen(vText), "UTF-8")

;handle \x method 2
vText := "Saut\xc3\xa9"
vText := StrReplace(vText, "\xc3", Chr(0xc3))
vText := StrReplace(vText, "\xa9", Chr(0xa9))
MsgBox, % vText
VarSetCapacity(vData, StrLen(vText))
Loop, Parse, vText
	NumPut(Ord(A_LoopField), &vData, A_Index-1, "UChar")
MsgBox, % StrGet(&vData, StrLen(vText), "UTF-8")
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder, roysubs and 275 guests