Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如何用“内部”封装脚本&“,与“外部”&引用@_String_Powershell - Fatal编程技术网

String 如何用“内部”封装脚本&“,与“外部”&引用@

String 如何用“内部”封装脚本&“,与“外部”&引用@,string,powershell,String,Powershell,我有一个脚本,其中包含@@: $myHtml = @" <html> ... </html> "@ 但我得到一个错误: 我可以通过从字符串中读取字节并将其转换为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 en

我有一个脚本,其中包含
@@

$myHtml = @" 
<html>
...
</html>
"@
但我得到一个错误:

我可以通过从字符串中读取字节并将其转换为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>
"@

'@
$string=@'
$myHtml=@”
...
"@
'@

$string = @'

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

'@