The PowerShell code:
$string = @'
Line 1
Line 3
'@
$string
Outputs:
Line 1
Line 3
But I want it to output:
Line 1
Line 3
How can I achieve that?
PowerShell Here-String is the method of inserting the multiple lines of the strings or the commands inside the enclosure, also known as the string array, and the best way of representing the data with the free text and string block is represented by the @” “@ with either single-quote or the Double-quote inside which ...
Use the `n Code Method The most common technique for forcing a line break is to insert `n just before the character where you want the break to occur. Note that the ` character is the backtick, not an apostrophe.
Backtick (`) character is the PowerShell line continuation character. It ensures the PowerShell script continues to a new line. To use line continuation character in PowerShell, type space at the end of code, use backtick ` and press enters to continue to new line.
You can call the PowerShell replace method on any string to replace any literal string with another. If the string-to-be-replaced isn't found, the replace() method returns nothing. You don't need to assign a string to a variable to replace text in a string.
In ISE works fine and in script
works too.
I don't remember where, but I read that is a bug in the console host code and empty lines are discarded when entered interactively for here-string.
At the moment I can't test if in Powershell V.3.0 console bug is fixed.
Link to the issue: http://connect.microsoft.com/PowerShell/feedback/details/571644/a-here-string-cannot-contain-blank-line
Workaround: add a backticks `
$string = @"
Line 1
`
Line 3
"@
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With