PowerShell: Double Quoted String
Double Quoted String
- Character sequence between
"QUOTATION MARK"
is Expandable String. (aka interpolated string) - Variable
$name
or${name}
or expression$(expr)
inside are replaced by their values.
$n = 4 $x = "I have $n cats" Write-Host $x # I have 4 cats
Expression is also expanded.
$x = "I have $(2+1) cats" Write-Host $x # I have 3 cats
Embed Variable
It should have the form
${name}
or
$name
The curly brackets can be omitted if there is no space after the name, nor some other non-letter character.
$x = 4 "${x}cats" # 4cats
Embed Expression
It should have the form
$(expr)
.
"$(3+4) cats" # 7 cats
Syntax for Newline
use literal newline or use `n
.
"line1
line2"
$x = "line1`nline2"
Syntax for Literal Dollar Sign
use `$
$x = 4 "`$x cats" # $x cats
Syntax for QUOTATION MARK
To include a QUOTATION MARK inside a QUOTATION MARK quoted string, precede it with GRAVE ACCENT `
"He said: `"yes`"" # He said: "yes"
Or precede it with QUOTATION MARK.
"He said: ""yes""" # He said: "yes"
Escape Character
PowerShell, string and regular expression
- PowerShell: String
- PowerShell: Single Quoted String
- PowerShell: Double Quoted String
- PowerShell: Here-String
- PowerShell: Escape Characters
- PowerShell: String Length
- PowerShell: Join String
- PowerShell: Split String
- PowerShell: Format String
- PowerShell: String Methods
- PowerShell: String Wildcards
- PowerShell: Regular Expression Operators
- PowerShell: Regex Result ($Matches)
- PowerShell: Regular Expression Syntax