4

I would like to set a string with special chars in it ($ for example). How can I save a string as a raw string?

$B = "A$$B" isn't saved as "A$$B".

3 Answers 3

6

If the string is in ' (single quotes) the variables ( like $x ) are not expanded.

Also, Powershell has here-strings much like verbatim strings in C#

http://blogs.msdn.com/b/powershell/archive/2006/07/15/variable-expansion-in-strings-and-herestrings.aspx

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

1 Comment

That link has died
3

maybe you can use the ` to escape chars (called 'backquote')

3 Comments

I'm not sure why someone down-voted this as it really is part of the answer. If you don't want any variable expansion, enclose the string in apostrophes. If you do want variable expansion, yet you also need some dollar signs in the string, enclose the string in quotation marks and escape any dollar signs you want to keep with accent grave.
Yea, this is one of the two ways to deal with this situation, and sometimes it is the only way.
agreed that this is valid, maybe the language like maybe you can use could have caused the downvote as people feel such things should be comments and not added as answers.
1

Use single quotes to set literal values in Powershell:

$B = 'A$$B' 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.