Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use a single quote in a PowerShell 'string'?

I want to include an apostrophe in my string. Is it possible to do without using double quotes?

'This is a quote. Can`'t I just include a single quote in it?' 'This is another quote that doesn\'t work' 
like image 813
Caleb Jares Avatar asked Jun 27 '12 16:06

Caleb Jares


People also ask

How do I add single quotes in PowerShell?

Write-Output "'$($Test)'" should yield the result you're after (note the double quotes to create a String and then the single quotes within that String). Also you need to enclose "Hello" in quotes $Test = "Hello" so that PowerShell interprets it as a String.

How do I add a quote to a string in PowerShell?

To include the double quotes inside of the string, you have two options. You can either enclose your string in single quotes or escape the double quotes with a symbol called a backtick. You can see an example of both below of using PowerShell to escape double quotes. Notice that "string" now includes the double quotes.

Can you use single quotes for string?

Both single (' ') and double (" ") quotes are used to represent a string in Javascript.

What is the difference between a single quote and double quote in PowerShell?

There is no such difference between the single quote (') and double quote(“) in PowerShell. It is similar to a programming language like Python. We generally use both quotes to print the statements.


1 Answers

'Escape a single quote '' using a double single quote' 

See the help for the quoting rules.

You can check out the help in the powershell command line by typing:

Get-Help about_Quoting_Rules 

It explains that backticks are interpreted literally in single-quoted strings.

Because the contents of single-quoted strings are interpreted literally, you cannot use the backtick character to force a literal character interpretation in a single-quoted string.

like image 136
zdan Avatar answered Sep 21 '22 14:09

zdan