如何在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.
推荐答案
用'0x'替换'\ u'并将其强制转换为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屋!
查看全文