1

I saw a code snippet here some time ago that dealt with PowerShell and HTML. An HTML code was passed into a variable. The beginning and the end were delimited with @" and "@. In a response, the @ delimiter was labelled with a specific term. Unfortunately, I did not save the post. Can someone tell me what this '@' delimitation is called and how exactly it is used?

2 Answers 2

1

See this article for more info on here strings which are what that is called. You can use a here string in that manner to define some html.

$html = @"
<body>
    <h1>Header 1</h1>
    <p>Paragraph</p>
</body>
@"

If you didn't use the here string you could run into errors parsing the html in various libraries because of the / that close tags.

Sign up to request clarification or add additional context in comments.

Comments

0

The syntax element you describe is a here-string expression:

@"
your string content goes here
...

and can span multiple lines!
"@

Like any other double-quoted string it's expandable (that is, you can embed variables and subexpressions):

@"
1 + 2 = $(1 + 2)!

... and the Process ID of this host application is ${PID}
"@

They can also be useful for single-line strings containing mixed verbatim quotation marks:

# no need to escape quotation marks
@"
The movie was titled "Jennifer's body"
"@

as opposed to escaping the quotation marks inline, which can become quite unreadable:

"The movie was titled `"Jennifer's body`""
"The movie was titled ""Jennifer's body"""  # this many double-quotes makes me dizzy
'The movie was titled "Jennifer''s body"'

Here-strings are documented in the about_Quoting_Rules help topic

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.