小编Chu*_*rly的帖子

如何在 PowerShell 字符串文字中编码 32 位 Unicode 字符?

这个堆栈溢出问题涉及 16 位 Unicode 字符。我想要一个支持 32 位字符的类似解决方案。有关各种 Unicode 图表的列表,请参阅此链接。例如,一系列 32 位字符是Musical Symbols

上面链接的问题中的答案不起作用,因为它将 System.Int32 值转换为 System.Char,这是一种 16 位类型。

编辑:让我澄清一下,我并不特别关心显示 32 位 Unicode 字符,我只想将字符存储在字符串变量中。

编辑 #2:我写了一个 PowerShell 片段,它使用标记答案及其评论中的信息。我本来想把它放在另一个评论中,但评论不能是多行的。

$inputValue = '1D11E'
$hexValue = [int]"0x$inputValue" - 0x10000
$highSurrogate = [int]($hexValue / 0x400) + 0xD800
$lowSurrogate = $hexValue % 0x400 + 0xDC00
$stringValue = [char]$highSurrogate + [char]$lowSurrogate
Run Code Online (Sandbox Code Playgroud)

Dour High Arch 的答案仍然值得称赞,因为它帮助我最终理解了代理对。

unicode powershell

5
推荐指数
2
解决办法
3900
查看次数

标签 统计

powershell ×1

unicode ×1