Removing line break powershell

房东的猫 提交于 2019-11-29 10:10:09

Okay, I think this should work. I was under the impression you wanted those underscores in the result.

$array -replace "`n|`r"

By default, 'Get-Content' command has the default delimiter of a new line '\n'. Create a costume parameter and then do your replace command. Hope this helps.

Get-ChildItem | Get-Content -Delimiter "~" | foreach { $_ -replace "`r|`n","" }

Well how about applying mjolinor's code at the $item level, e.g.:

foreach ($item in $array) {
  $item -replace '^|$','_'
}

Although I expect the same result you are already getting, there are newlines embedded in your string.

I'm not able to setup the same condition in $array myself, maybe you could post that code.

Does this work?:

foreach ($item in $array) {
  $item.Trim() -replace '^|$','_'
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!