如何在 PowerShell 中将文本居中? WindowWidth
显然不存在,那么有没有办法让文本保持居中?
我们想要这个输出:
*
***
*****
*******
所以我写了
for ($i=1; $i -le 7; $i+=2)
{
write-host("*" * $i)
}
但是我们得到
*
***
*****
*******
最佳答案
function Write-HostCenter { param($Message) Write-Host ("{0}{1}" -f (' ' * (([Math]::Max(0, $Host.UI.RawUI.BufferSize.Width / 2) - [Math]::Floor($Message.Length / 2)))), $Message) }
Write-HostCenter '*'
Write-HostCenter '***'
Write-HostCenter '*****'
关于powershell - 有没有办法在 PowerShell 中使文本居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48621267/