views:

775

answers:

1

How can I encode the Unicode character U+0048 (H), say, in a Powershell string? In C# I would just do this: "\u0048", but that doesn't appear to work in Powershell.

+5  A: 

Replace '\u' with '0x' and cast it to System.Char:

PS > [char]0x0048
H

Shay Levy
Thanks. That works. I can use it like this: [char]0x0048 + "ello", which gives "Hello".
dangph
You can even write a little function: function C($n) {[char][int]"0x$n"}. Which you can use in a string as follows: "$(C 48)ello World." Not ideal but probably a little closer to the \u escape.
Joey