如何在 PowerShell 字符串文字中对 Unicode 字符代码进行编码? [英] How do I encode Unicode character codes in a PowerShell string literal?
本文介绍了如何在 PowerShell 字符串文字中对 Unicode 字符代码进行编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 PowerShell 字符串中对 Unicode 字符 U+0048 (H) 进行编码?
How can I encode the Unicode character U+0048 (H), say, in a PowerShell string?
在 C# 中,我会这样做:"u0048"
,但这在 PowerShell 中似乎不起作用.
In C# I would just do this: "u0048"
, but that doesn't appear to work in PowerShell.
推荐答案
将 'u' 替换为 '0x' 并将其转换为 System.Char:
Replace 'u' with '0x' and cast it to System.Char:
PS > [char]0x0048
H
您还可以使用$()"语法将 Unicode 字符嵌入到字符串中:
You can also use the "$()" syntax to embed a Unicode character into a string:
PS > "Acme$([char]0x2122) Company"
AcmeT Company
其中 T 是 PowerShell 对非注册商标字符的表示.
Where T is PowerShell's representation of the character for non-registered trademarks.
这篇关于如何在 PowerShell 字符串文字中对 Unicode 字符代码进行编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文