Search

A here-string cannot contain blank line by Dardenne Laurent

Active

6
0
Sign in
to vote
Type: Bug
ID: 571644
Opened: 6/29/2010 6:04:28 AM
Access Restriction: Public
1
Workaround(s)
4
User(s) can reproduce this bug
In a here-string, the blank line are removed.

The end of line (LF) in a here-string, is not equal to System.Environment.NewLine(CR+LF).
Details (expand)
How often does this happen?
Always Happens

Have you seen this problem before in this product?

I don't know if this issue existed previously
Reproduction Steps
ps> $Test=@"

first

next
end


"@

ps> $Test
#result
first
next
end
#end of text

ps> $Test -replace "`r`n","@@"
#result
first
next
end
#end of text

ps> $Test -replace "`n","@@"
#result
first@@next@@end
#end of text

ps> [byte[]][char[]]$Test
#result
102
105
114
115
116
10
110
101
120
116
10
101
110
100
#end of text
Expected Results
For $Test=@"

first

next
end


"@

#begin of text

first

next
end


#end of text
File Attachments
0 attachments
Sign in to post a comment.
Posted by jrich on 9/8/2010 at 7:17 AM
Oddly enough, This works as expected in ISE but not the console.
Posted by Michael_B_Smith on 8/25/2010 at 8:07 AM
This is true in interactive shell mode. When a line continuation character is displayed (">>"), if an empty line (or a line containing all spaces -- I presume it's actually a line containing all whitespace, but I didn't test) is entered, then the shell "swallows" the line. So...

$s = @'
aa

bb

cc
'@

is actually stored as

$s = @'
aa
bb
cc
'@

This error exists for both single and double quoted here-strings.

When executing a script file, this does not occur.
Sign in to post a workaround.
Posted by Christian.Bari on 1/24/2013 at 7:50 AM
If needed add a backticks in the empty line:

$string = @"
Line 1
`
Line 3
"@