在Powershell中编写十六进制转义字符

Bur*_*r0k 4 powershell-3.0

有没有办法在Powershell中写这样的东西?(Linux将与Perl一起使用)

char foo = '\x41';
Run Code Online (Sandbox Code Playgroud)

我需要在我的一个程序中输入一些不可打印的字符

Per*_*t28 6

你可以通过将int转换为char来实现.

带小数:

 $foo = (65 -as [char])
Run Code Online (Sandbox Code Playgroud)

来自hexa:

 $foo = (0x41 -as [char])
Run Code Online (Sandbox Code Playgroud)

两者都将设置$fooA


小智 5

I\xe2\x80\x99d 喜欢提供一种不同于十六进制转换的方法。PowerShell 7 支持 Unicode 字符编码,而不是使用十六进制(请参阅文章about_special_characters > Unicode 字符)。因此,如果 x041 为拉丁文大写 A,则 Unicode 等效项为"`u{41}". Microsoft 文档示例通过此示例进行了演示:("`u{2195}"请注意反引号位于字母之前)。

\n