Monthly Archive

Categories

Scripting Games Comments – Writing Lines

No - not what you did at school when you got caught!

Looking at the scripts submitted for the games I’ve seen a number of ways of writing out a new line – including calls to the System.Environment class.

We normally use Write-Host to write a line

Write-Host “ some text”   

PowerShell has a special character `n that can be used to throw a new line

Write-Host “`n” 

or we can combine it with the text

Write-Host “`n some text”

The only draw back to this is that it may throw two lines instead of one!

The simplest and quickest way to output a single blank line is

“”

A string on a line by itself is treat as output.

I’ve also seen

Write-Host “*************************”

and similar

why not try

Write-Host $("*"*25)

If you multiply a string you get it extended to that number of repeats

PS> Write-Host $("*-"*25)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

There are lots of ways to make PowerShell easier – hope these help

Leave a Reply