How to break lines in PowerShell?

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' 

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"

I think I found it. All you have to do is type in "`n" (WITH THE QUOTATION MARKS!)

Thanks!


Just in case someone else comes across this, to clarify the answer `n is grave accent n, not single tick n


If you are using just code like this below, you must put just a grave accent at the end of line `.

docker run -d --name rabbitmq `
           -p 5672:5672 `
           -p 15672:15672 `
           --restart=always `
           --hostname rabbitmq-master `
           -v c:\docker\rabbitmq\data:/var/lib/rabbitmq `
           rabbitmq:latest