Code: Select all
Test := ""
. UnicodeToHex("∞") "`r`n"
. UnicodeToHex("∞", "Upper") "`r`n"
. "`r`n"
. UnicodeToHex("∞", "0x") "`r`n"
. UnicodeToHex("∞", "0x Upper") "`r`n"
. "`r`n"
. UnicodeToHex("abcd") "`r`n"
. UnicodeToHex("abcd", "Dlm(/)") "`r`n"
. UnicodeToHex("abcd", "Dlm(_)") "`r`n"
. UnicodeToHex("∞∞∞", "Dlm( _ )") "`r`n"
. UnicodeToHex("∞∞∞", "Dlm( _ ) Upper") "`r`n"
. UnicodeToHex("∞∞∞", "Dlm( _ ) Upper 0x") "`r`n"
. "`r`n"
. UnicodeToHex("abcd", "Dlm(`r`n) 0x") "`r`n"
. "`r`n"
. UnicodeToHex("abcd", "Dlm( - ) Base1") "`r`n"
. UnicodeToHex("abcd", "Dlm( - ) Base3") "`r`n"
. UnicodeToHex("abcd", "Dlm( - ) Base4") "`r`n" ;Base4 is what is needed for Unicode (16^4 = 65536 chars)
. UnicodeToHex("abcd", "0x Dlm( - ) Base4") "`r`n" ;Base4 is what is needed for Unicode (16^4 = 65536 chars)
. UnicodeToHex("abcd", "Dlm( - ) Base5") "`r`n"
. UnicodeToHex("abcd", "Dlm( - ) Base10") "`r`n"
gui, add, edit, w450 h350 +HwndEditId,
ControlSetText , , % Test, % "ahk_id" EditId
gui, show
return
guiclose: ;___________ gui close __________
exitapp
UnicodeToHex(String, Options := "") ;________________ UnicodeToHex(function) - v1.0 _____________
{
if RegExMatch(Options, "i)0x") ;"i)" enable case insensitive
Pre := "0x"
if RegExMatch(Options, "i)Upper") ;"i)" enable case insensitive
Opt .= "X"
else
Opt .= "x"
RegExMAtch(Options, "si)Dlm\((.*?)\)", Match)
Dlm := Match1
RegExMAtch(Options, "i)Base([1-9]\d*)", Match)
Base := Match1
loop
{
Char := SubStr(String, a_index, 1) ;"a_index" = pos, "1" = Length
if (Char == "") ;"==" is case sensitive
return, HexString
else
{
HexChar := Format("{1:" Opt "}", ord(Char))
if (Base != "")
{
loop, % Base - StrLen(HexChar)
HexChar := "0" HexChar
}
HexString .= Pre HexChar Dlm
;x or X, Unsigned hexadecimal integer; "x" for "abcdef" format or "X" for "ABCDEF" format.
;The "0x" prefix is not included unless the "#" flag is used, example: {1:#x}
}
}
}