powershell - 字符串中的Powershell unicode字符
问题描述
我已阅读 Microsoft powershell 官方文档,并找到了以下示例:
"`u{0048}"
它应该显示一个 H
但是,就我而言,它显示:
你{0048}
我不需要替代品,我想了解为什么它不起作用。
谢谢
解决方案
转义序列已添加到 PowerShell 6 中的字符串扩展语法中,并且在任何版本的 Windows PowerShell`u{XXXX}
中都不会被识别。
在 Windows PowerShell 中,您可以将数值转换[char]
为子表达式:
"$([char]0x48)"
或使用-as
运算符转换为[char]
:
0x48 -as [char]
# or
0x48 -as 'char'
如果您尝试在不使用,或在源代码中生成[char]
值,则 PowerShell 中有很多机会,的别名和 member-invocation-via-wildcards 特别方便:H
h
H
[
]
ForEach-Object
# grab the `h` in `$env:path`
(dir env:pat?).Name.GetEnumerator()|select -Last 1
# reflect against another existing [char] to get the type
$g = 'g'|% ToC?ar ($null)
0x48 -as $g.GetType()
# generate char range between G and I, filter out G and I (pwsh >6.1 only)
'G'..'I'|?{$_-notin'G','I'}
推荐阅读
- php - Laravel 6 错误 - Illuminate\Contracts\Container\BindingResolutionException 目标类不存在
- angular - 角度形式,setValue 后无法更改值
- wpf - 默认复制模板上的 MahApps Metro SplitButton 错误
- flutter - 装载时颤振重载功能
- php - 如何使用 PHP 更新/编辑 JSON
- php - 如何使用 WooCommerce 订阅插件启用货到付款方式
- python - 如何计算给定字符串中两个子字符串的出现而不在python中重叠?
- python - 每年计算熊猫数据框中的相似字符串值
- makefile - 目标位置如何影响 makefile 的行为
- javascript - 没有找到依赖翻转工具包