本文介绍了如何在 PowerShell 中创建 printf 效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何让我的 PowerShell 脚本随着脚本的进展以表格格式打印信息.
How can I get my PowerShell script to print the info in tabular format as the script progresses.
在 bash 中,我会这样做
In bash I would do this by
printf "%s\t%-15.15s" "Locale" "Jar"
if($verbose);then
printf "%-15.15s %-15.15s" "HelpSet" "Exception"
fi
printf "\t%s\n" "Status"
...
printf "%s\t%-15.15s" $locale $helpFileName
if($verbose); then
printf "%-15.15s %-15.15s" "$helpSetName" ${exclusion[$helpFileName]}
fi
status="OK"
...
if ($fixed); then
status="CORRECTED"
fi
printf "\t%s\n" $status
得到
Locale Jar HelpSet Exception Status
de help_D150 help_D150 CORRECTED
es help_D150 help_D150 OK
fr help_D150 help_D150 OK
it Locale folder not found
nl help_D150 help_D150 CORRECTED
谢谢
推荐答案
在您的 PowerShell 控制台中试试这个:
Try this out in your PowerShell console:
"{0}`t{1,-15}{2,-15}{3,-15}" -f "Locale", "Jar", "HelpSet", "Exception"
您可以在 PowerShell 中轻松使用字符串格式.
You can use string formatting quite easily from PowerShell.
-f
运算符是String.Format
函数,包括所有标准和自定义格式化 .NET 类型支持.
The
-f
operator is a PowerShell short cut to the String.Format
function, including all the standard and custom formatting .NET types support.
这篇关于如何在 PowerShell 中创建 printf 效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!