什么是@"运算符? [英] What is @” operator?

查看:128
本文介绍了什么是@"运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在互联网上搜索了这意味着什么:@",分别包括 @".

I searched all over the internet for what this means: @", including @ and " individually.

在这个代码中:

$Win32ShowWindowAsync = Add-Type –memberDefinition @" 
[DllImport("user32.dll")] 
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); 
"@ -name "Win32ShowWindowAsync" -namespace Win32Functions –passThru

我也不断收到上面第一行的错误消息:

I also keep on getting this error message for the first line above:

White space is not allowed before the string terminator.

我将 " 改为 ",但没有成功.

I changed " to ", but no luck.

那么这些符号在 Powershell 中是什么意思呢?

So what do those symbols mean in Powershell?

谢谢

推荐答案

您正在查看 here-string.错误来自格式错误的 here-string.

You are looking at a here-string. The error is from a malformed here-string.

您上面复制的代码可以正常工作.开头必须完成该行,而 here 字符串的结尾必须单独在它自己的行上.他们在问题中的代码中.我可以通过在终止符 "@ 之前添加一些空格来创建您的错误.

The code you have above copies and works just fine as is. The start must finish the line and the end of the here string must be alone on it's own line. Which they are in your code in the question. I can create your error by adding some spaces before the terminator "@.

$Win32ShowWindowAsync = Add-Type –memberDefinition @"
[DllImport("user32.dll")] 
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); 
    "@ -name "Win32ShowWindowAsync" -namespace Win32Functions –passThru

我会仔细检查您实际使用的代码.猜猜你会发现像错误所暗示的那样前导空格.您链接到的页面中有一条评论是关于从代码中删除该空格.您从具有领先空白的站点复制并粘贴.

I would double check the code you are actually using. Guessing you will find leading whitespace like the error is suggesting. There is a comment in the page you linked to that talks about removing that whitespace from the code. You copied and pasted from that site which had leading whitespace.

引用 devcentral.f5.com

here-string 用于将脚本中的大块内联文本嵌入到单个字符串文字中.这与 C# 中的功能非常相似,但不同之处在于,在 PowerShell 中,here-string 在行尾开始,终止序列必须在行首.

A here-string is used to embed large chunks of text inline in a script into a single string literal. This is very similar to a feature in C#, but the difference is that in PowerShell the here-string begins at the end of a line and the terminating sequence must be at the beginning of a line.

使用双引号将允许变量扩展,而单引号则不允许.就像 PowerShell 中的普通字符串一样.

Using double quotes will allow for variable expansion whereas single quotes will not. Just like normal strings in PowerShell.

我也看到了一些巧妙的引语,但就像你说的那样,当你改变它们时,这没有帮助.一般来说,留意那些.

I also see smart quotes but, like you said, that didn't help when you changed them. In general keep an eye out for those.

这篇关于什么是@"运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆