Is there a way to center text in PowerShell

前端 未结 3 1390
长发绾君心
长发绾君心 2021-01-14 23:46

How can we center text in PowerShell? WindowWidth doesn\'t exist apparently, so is there a way somehow to keep the text centered?

We want this output :<

3条回答
  •  隐瞒了意图╮
    2021-01-14 23:57

    You can calculate the spaces you need to add and then include them as follows:

    $Width = 3
    
    for ($i=1; $i -le 7; $i+=2)
    {   
        Write-Host (' ' * ($width - [math]::floor($i / 2))) ('*' * $i)
    }
    

提交回复
热议问题