【问题标题】:Powershell Replace '"`n' don't workPowershell替换'"`n'不起作用
【发布时间】:2018-07-31 17:58:15
【问题描述】:

我需要用powershell替换字符串

`"`n  (`n = Line feed)`

在“;”中作为示例,但是

`(Get-Content $file -raw).replace('"`n', ';')| Set-Content $filenew -force`

没用

有人可以帮助我吗?谢谢。

feva

【问题讨论】:

    标签: powershell replace


    【解决方案1】:

    这是换行符:

    `n
    

    所以你很接近了!

    示例

    $input = @"
    one
    two
    three
    "@
    
    $input -replace "`n", ";"
    

    结果

    one;two;three
    

    您的代码

    (Get-Content $file -Raw).Replace('`n', ';') |
        Set-Content $filenew -Force
    

    【讨论】:

      【解决方案2】:

      问题是n The String is "n前面的“包含”

      $input -replace ""`n", ";"
      

      不会工作。

      【讨论】:

        猜你喜欢
        • 2022-01-25
        • 2018-03-09
        • 1970-01-01
        • 1970-01-01
        • 2019-05-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-11-11
        相关资源
        最近更新 更多