Reputation: 141
I want to replace my linebreaks with a character.
Before:
Test1
Test2
Test3
Test4
After:
Test1|Test2|Test3|Test4
For this I tried following Script:
$a=Get-Content "C:\Users\Administrator\Desktop\test2.txt"
$a=$a.Replace("`r`n","|")
But this gives me the following:
Test1 Test2 Test3 Test4
What did I wrong? I ask a similar question couple of hours ago: Replace Word with a Linebreak
But it dont help me at my current Problem.
Upvotes: 1
Views: 78
Reputation: 26180
Try this :
$a=Get-Content "C:\Users\Administrator\Desktop\test2.txt" -raw
$a=$a -Replace '\n', '|'
the -raw parameter will make the content to be threated as a single string
Upvotes: 1