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.
views:
775answers:
1
+5
A:
Replace '\u' with '0x' and cast it to System.Char:
PS > [char]0x0048
H
Shay Levy
2009-06-29 07:26:42
Thanks. That works. I can use it like this: [char]0x0048 + "ello", which gives "Hello".
dangph
2009-06-29 07:39:31
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
2009-06-29 09:29:13