von
@Rohwedder
Code: Select all
;- Format multiple characters by char code? / Rohwedder
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=109066
;-
aa={"name":"j\u00fcrgen","name_sanitized":"J\u00fcrgen","country":"","gender":"male","samples":9431,"accuracy":99,"duration":"12ms","credits_used":1}
ab:=decode_utf8(aa)
msgbox,%ab%
return
;_
decode_utf8(charcode_string) {
spo := 1
out := ""
while (fpo:=RegexMatch(charcode_string, "i)\\u([0-9A-F]{1,6})", m, spo))
{
out .= SubStr(charcode_string, spo, fpo-spo)
spo := fpo + StrLen(m)
if (m1)
out .= Chr("0x" m1)
}
return out SubStr(charcode_string, spo)
}
;=====================================================================
Beispiel in einem loop ... ( muss vorerst diese richtigen Linien finden)
Code: Select all
#Warn
e:=""
e4=
(
{"name":"j\u00fcrgen","name_sanitized":"J\u00fcrgen","country":"","gender":"male","samples":9431,"accuracy":99,"duration":"12ms","credits_used":1}
{"name":"j\u00fcrgen","name_sanitized":"\u4f60\u597d","country":"","gender":"female","samples":9430,"accuracy":98,"duration":"12ms","credits_used":1}
{"name":"j\u00fcrgen","name_sanitized":"星期日 十一月","country":"","gender":"male","samples":9429,"accuracy":97,"duration":"12ms","credits_used":1}
)
loop,parse,e4,`n,`r
{
aa:=a_loopfield
ab:=decode_utf8(aa)
stringreplace,ab,ab,`",,all
StringSplit,a,ab,`,
StringSplit,b,a2,`:
StringSplit,c,a4,`:
if (c2="male")
c2:="männlich"
if (c2="female")
c2:="weiblich"
StringSplit,d,a6,`:
StringSplit,e,a5,`:
e .= b2 . ": " . c2 . " (Genauigkeit: " . d2 . " / Proben: " . e2 . ")`r`n"
}
msgbox,%e%
return
;------------------
;- Format multiple characters by char code? / Rohwedder
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=109066
;-
decode_utf8(charcode_string) {
spo := 1
out := ""
while (fpo:=RegexMatch(charcode_string, "i)\\u([0-9A-F]{1,6})", m, spo))
{
out .= SubStr(charcode_string, spo, fpo-spo)
spo := fpo + StrLen(m)
if (m1)
out .= Chr("0x" m1)
}
return out SubStr(charcode_string, spo)
}
;=====================================================================
RESULT :
Code: Select all
Jürgen: männlich (Genauigkeit: 99 / Proben: 9431)
你好: weiblich (Genauigkeit: 98 / Proben: 9430)
星期日 十一月: männlich (Genauigkeit: 97 / Proben: 9429)