Reputation: 136
Is there any way to write something like this in Powershell? (Linux would be with Perl)
char foo = '\x41';
I need to input some non-printable characters to one of my programs
Upvotes: 7
Views: 8240
Reputation: 396
I’d like to offer a different approach than casting as hex. Instead of using hex, PowerShell 7 supports Unicode character encoding (see article about_special_characters > Unicode characters). So, with x041 as Latin capital A, the Unicode equivalent would be "`u{41}"
. The Microsoft docs example demonstrated with this example: "`u{2195}"
(note the backtick precedes the letter).
Upvotes: 5
Reputation: 11327
You can do it by casting an int to char.
With a decimal number :
$foo = (65 -as [char])
And from hexa :
$foo = (0x41 -as [char])
Both will set $foo
to A
Upvotes: 6