string - 如何将包含单引号的输出放入 Powershell 中的字符串中?
问题描述
我很难将包含单引号 ('') 的输出转换为变量。输出是这样的:
Warning: Invalid character is found in given range. A specified range MUST
Warning: have only digits in 'start'-'stop'. The server's response to this
Warning: request is uncertain.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:--
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0{
"total": 2,
"subtotal": 2,
"page": 1,
...
我认为这个问题出在第一个单引号中。我已经尝试使用@''@、@('') 创建带有单引号的变量,但是这些形式都不起作用。我怎样才能把它放在一个变量中?
解决方案
使用here-string
,引号按字面意思解释,参见:Here-strings
$x = @'
Warning: Invalid character is found in given range. A specified range MUST
Warning: have only digits in 'start'-'stop'. The server's response to this
Warning: request is uncertain.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:--
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0{
"total": 2,
"subtotal": 2,
"page": 1,
...
'@
推荐阅读
- python - 如何在按钮单击另一个小部件时显示小部件
- c++ - `fout.write(reinterpret_cast
(&e), sizeof(e) );` 为什么这里要转换成`const char*`? - javascript - 角度映射对象
- c# - 将应用程序上传到弹性 beantalk AWS 并使 ebextensions 文件选择模式发布或测试
- python - 从 Keras 的 BatchNormalization 派生的类的用途不明确
- python - 如何从 Python 脚本创建日志文件并保存所有运行日志
- etl - 数据仓库和原子性很少共存
- c++ - ESP32 FreeRTOS 从另一个任务中删除一个任务
- azure-functions - 具有 Azure 函数调用完成阶段的数据工厂
- javascript - 为什么我的三元运算符会破坏我的登录路由?