,则需要后者
生成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