如何在PowerShell中断行?(How to break lines in PowerShell?)

编程入门 行业动态 更新时间:2024-10-27 12:24:45
如何在PowerShell中断行?(How to break lines in PowerShell?)

我是PowerShell的全新功能,并且在循环中连接一个字符串,如果发生特殊情况,我应该插入一个换行符...我该怎么做?

基本上寻找相当于\n 。

$str = ""
foreach($line in $file){
  if($line -Match $review){ #Special condition
    $str += ANSWER #looking for ANSWER
  }
  #code.....
}
 

到目前为止我已经试过了

"\n" '\n' "\N" '\N' "\r" '\r' "\R" '\R' '`n' '`r' '-n' '-r'

I am [completely new to PowerShell and] concatenating a string in a loop, if a special condition occurs I should insert a line break...how can I do this?

Basically looking for the equivalent of \n.

$str = ""
foreach($line in $file){
  if($line -Match $review){ #Special condition
    $str += ANSWER #looking for ANSWER
  }
  #code.....
}
 

So far I have tried

"\n" '\n' "\N" '\N' "\r" '\r' "\R" '\R' '`n' '`r' '-n' '-r'

最满意答案

尝试`n ( 不是 '`n' )

有关转义字符的完整列表,请参阅:

Help about_Escape_character

代码应该是

$str += "`n"

Try "`n" with double quotes. (not single quotes '`n' )

For a complete list of escaping characters see:

Help about_Escape_character

The code should be

$str += "`n"

更多推荐

本文发布于:2023-07-21 23:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1214862.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   PowerShell   lines   break

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!