help! powershell and unicode hex...

Soldato
Joined
25 Mar 2004
Posts
16,007
Location
Fareham
Hi all,

Have a bit of an odd one but it's driving me crazy, I need to convert a hex character to the correct text value, for example in PowerShell you can do this:

$Hex = 0xc3a1
$Text = [Convert]::ToChar($Hex) ; $Text

This returns the string value 'A' correctly. The problems occur if I want to use another character such as á (see http://www.fileformat.info/info/unicode/char/e1/index.htm).

á uses the UTF-8 (hex) value:

0xC3 0xA1 (c3a1)

What I need to get my code working is this instead:

UTF-16 (hex)

0x00E1 (00e1)

If I run my code against 0xc3a1 instead it returns '?' because it converts it to a ? character. $Hex = 0xc3a1 Returns value 50081 which is incorrect.

Any ideas how I can convert the hex value c3a1 into the correct value e1 / 225 instead of how this is currently being calculated?

Cookie to the first one to solve this!

Powershell can use the general .net framework parameters for conversion, I am sure I am just missing something obvious here!

Thanks!
 
Last edited:
Back
Top Bottom