meomeo192

Hex to string Unicode

6 posts in this topic

#1 ·  Posted

Hello, I have a hex string (this is '4CC6AFC6A04E472056C4824E205448C38C4E'), i want convert it to Unicode string, i used function _HexToString, but it does not return a Unicode string (it must be 'Lương Văn Thìn')

This is the answer for me, if code via C#:;

Quote

private string ConvertHexStrToUnicode(string hexString)

        {

            int length = hexString.Length;

            byte[] bytes = new byte[length / 2];

 

            for (int i = 0; i < length; i += 2)

            {

                bytes[i / 2] = Convert.ToByte(hexString.Substring(i, 2), 16);

            }

            return Encoding.UTF8.GetString(bytes);

        }

But i don't know do it in AutoIT, please help me.

Thank you very much.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this:

#include <WinAPI.au3>
Global $bin = Binary("0x4CC6AFC6A04E472056C4824E205448C38C4E")
Global $tString = DllStructCreate("ubyte txt[" & BinaryLen($bin) & "]")
$tString.txt = $bin
ConsoleWrite(_WinAPI_MultiByteToWideChar($tString, 65001, Default, True) & @CRLF)

 

Edited by UEZ
1 person likes this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#3 ·  Posted

@UEZ Thanks you very much.

Share this post


Link to post
Share on other sites

#4 ·  Posted

BinaryToString("0x4CC6AFC6A04E472056C4824E205448C38C4E", 4)

 

1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

@InnI perfect code, with code of @UEZ i creat a function, but it not work completely.

Quote

Func ConvertHexToString($STextHex)
   If StringLeft($STextHex,2)<>'0x' Then
      $STextHex='0x'&$STextHex
   EndIf
   Return BinaryToString($STextHex, 4)
EndFunc

#include <WinAPI.au3>
Func ConvertHexToString2($STextHex)
   If StringLeft($STextHex,2)<>'0x' Then
      $STextHex='0x'&$STextHex
   EndIf
   Global $bin = Binary($STextHex)
   Global $tString = DllStructCreate("ubyte txt[" & BinaryLen($bin) & "]")
   $tString.txt = $bin
   Return _WinAPI_MultiByteToWideChar($tString, 65001, Default, True)
EndFunc

 

Edited by meomeo192

Share this post


Link to post
Share on other sites

#6 ·  Posted

#include <WinAPI.au3>

MsgBox(0, "",   _
                "Hello World" & @CRLF & _
                ConvertHexToString(Binary("0xE0B8AAE0B8A7E0B8B1E0B8AAE0B894E0B8B5E0B88AE0B8B2E0B8A7E0B982E0B8A5E0B881")) & @CRLF & _
                ConvertHexToString(Binary("0xCE93CEB5CEB9CEAC20CF83CEBFCF8520CE9ACF8CCF83CEBCCEB5")) & @CRLF & _
                ConvertHexToString(Binary("0x4368C3A06F207468E1BABF206769E1BB9B69")) & @CRLF & _
                ConvertHexToString(Binary("0xE0A4A8E0A4AEE0A4B8E0A58DE0A4A4E0A58720E0A4A6E0A581E0A4A8E0A4BFE0A4AFE0A4BE")) & @CRLF & _
                ConvertHexToString(Binary("0xE4BDA0E5A5BDEFBC8CE4B896E7958C")))

MsgBox(0, "",   _
                "Hello World" & @CRLF & _
                ConvertHexToString2(Binary("0xE0B8AAE0B8A7E0B8B1E0B8AAE0B894E0B8B5E0B88AE0B8B2E0B8A7E0B982E0B8A5E0B881")) & @CRLF & _
                ConvertHexToString2(Binary("0xCE93CEB5CEB9CEAC20CF83CEBFCF8520CE9ACF8CCF83CEBCCEB5")) & @CRLF & _
                ConvertHexToString2(Binary("0x4368C3A06F207468E1BABF206769E1BB9B69")) & @CRLF & _
                ConvertHexToString2(Binary("0xE0A4A8E0A4AEE0A4B8E0A58DE0A4A4E0A58720E0A4A6E0A581E0A4A8E0A4BFE0A4AFE0A4BE")) & @CRLF & _
                ConvertHexToString2(Binary("0xE4BDA0E5A5BDEFBC8CE4B896E7958C")))

Func ConvertHexToString($STextHex)
   If StringLeft($STextHex,2)<>'0x' Then $STextHex='0x'&$STextHex
   Return BinaryToString($STextHex, 4)
EndFunc

Func ConvertHexToString2($STextHex)
    If Not IsBinary($STextHex) Then Return SetError(1, 0, "")
    If StringLeft($STextHex,2) <> '0x' Then $STextHex = '0x' & $STextHex
    Local $tString = DllStructCreate("ubyte txt[" & BinaryLen($STextHex) & "]")
    $tString.txt = $STextHex
    Return _WinAPI_MultiByteToWideChar($tString, 65001, Default, True)
EndFunc

 


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now