How to Convert a Hex String to Char
Keywords: hex decimal ascii num2char
Question:
How can I convert a hex string to char ?
ex: x'41' = "A"
Answer:
origstring="x'4a'"
hexstring=origstring
;remove x's and single quotes
hexstring=StrReplace(hexstring,"x","")
hexstring=StrReplace(hexstring,"'","")
;force to two digits
hexstring=strfix(hexstring,"0",2)
h1=strsub(hexstring,1,1)
h2=strsub(hexstring,2,1)
h1=StrIndexnc("123456789abcdef",h1,0,@fwdscan)
h2=StrIndexnc("123456789abcdef",h2,0,@fwdscan)
DaNum=h1*16+h2
DaChar=Num2Char(DaNum)
Message(origstring,DaChar)
or by using the WILX extender, avoid some messy math
AddExtender("wilx34i.dll")
origstring="x'4a'"
hexstring=origstring
;remove x's and single quotes
hexstring=StrReplace(hexstring,"x","")
hexstring=StrReplace(hexstring,"'","")
DaNum=xhex(hexstring)
DaChar=Num2Char(DaNum)
Message(origstring,DaChar)
Article ID: W14658
Filename: How to Convert a Hex String to Char.txt