在Clxml文件中替换新行



生成clxml文件后:

[string]$myString = 'foobar' | Export-Clixml -Path C:Filestest.clxml

我试图在右键关闭锚点>之后删除线路断裂。我尝试了:

(Get-Content C:Filestest.clxml) -replace "`n", "" | Set-Content C:Filestest.clxml

也尝试使用-replace r,但这会从文件中删除r字符。

我在做什么错?

Get-Content返回 array 握住每条线(不包含任何行馈送)。

Set-Content将您的线数字写给单个文件,将它们分开。

意味着您应该做以下操作以获取想要的东西:

(Get-Content C:Filestest.clxml) -join "" | Set-Content C:Filestest.clxml

您的问题是,在您的测试中,没有新的替换。Get-Content正在返回一个字符串 array ,该数组被视为呈现时在屏幕上有新线。为了将它们实际操作以操纵字符串,请尝试其中之一。

(Get-Content C:Filestest.clxml -Raw) -replace "`n" | Set-Content C:Filestest.clxml
(Get-Content C:Filestest.clxml | Out-String) -replace "`n" | Set-Content C:Filestest.clxml

如果您的PS 2.0

,则需要后者

最新更新