gpt4 book ai didi

string - 如何用内部@""@封装脚本,用外部@""@

转载 作者:行者123 更新时间:2023-12-01 08:01:38 24 4
gpt4 key购买 nike

我有一个包含 @""@ 的脚本:

$myHtml = @" 
<html>
...
</html>
"@

我想将所有此脚本转换为带有 @""@ 的字符串到变量。

这是我试过的:

$string = @"

$myHtml = @"
<html>
...
</html>
"@

"@

但是我得到一个错误:
enter image description here

我可以通过读取字符串中的字节并将其转换为 ASCII 来解决此问题:

# Read the entire file to an array of bytes.
$bytes = [System.IO.File]::ReadAllBytes("path_to_my_script")
# Convert to a text assuming ASCII encoding.
$text = [System.Text.Encoding]::ASCII.GetString($bytes)

但我想学习如何使用内部 @""@ 和外部 @""@ 封装脚本。

最佳答案

只需将字符串引号更改为单引号而不是双引号:

$string = @'

$myHtml = @"
<html>
...
</html>
"@

'@

参见 about_Quoting_Rules

关于string - 如何用内部@""@封装脚本,用外部@""@,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47387869/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com