arrays - 填充表格数据的打印输出

我知道这可能很简单,但我在一个文件中保存了一些数据:

Artichoke

Green Globe, Imperial Star, Violetto

24" deep

Beans, Lima

Bush Baby, Bush Lima, Fordhook, Fordhook 242

12" wide x 8-10" deep

我希望能够格式化成一个漂亮的 TSV 类型的表格,看起来像这样:

    Name  | Varieties    | Container Data
----------|------------- |-------
some data here nicely padded with even spacing and right aligned text 

最佳答案

试试 String#rjust(width) :

"hello".rjust(20)           #=> "               hello"

https://stackoverflow.com/questions/603047/

相关文章:

html - 在 Rails 中,如何在文本区域中允许一些 html?

php - 保持我的 PHP 漂亮

formatting - 好的评论用例

python - 在列表上迭代格式字符串

powershell - 在 PowerShell 中导出为 CSV 时如何指定列顺序?

javascript - 使用纯 JavaScript 将电话号码格式化为用户类型

perl - 在 Perl 中处理非常大的数字时,如何禁用科学记数法?

string - 固定宽度数字格式化python 3

sql - 总是在 SQL 中显示小数位?

javascript - 不允许在 textarea 中换行