是否有与 C++ 等效的 Ruby? std::setw(int) 函数?
我正在将一些文本表输出到终端,并且希望能够使用 C++ std::setw() 函数之类的功能为我的输出提供填充,而不是猜测所需的空格或制表符数量。在我开始拼凑一些东西来执行此操作之前,是否已经有一个函数或 Ruby Gem 可以执行此操作?
std::setw() 适合那些需要一些蜘蛛网流出的人(像我一样) http ://www.cplusplus.com/reference/iostream/manipulators/setw/
我目前使用的是 Ruby 1.8,因此最好有一个与其兼容的解决方案。
I am outputting some text tables to a terminal and would like to be able to use something like the C++ std::setw() function to provide padding for my output rather than guessing at the number of spaces or tabs required. Before I go knock together something to do this, is there already a function or Ruby Gem which does this?
Std::setw() for those who need a few cobwebs flow out (like me) http://www.cplusplus.com/reference/iostream/manipulators/setw/
I am using Ruby 1.8 at present so a solution compatible with that would be preferable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是同一个接口(思维略有不同),但如果我正确理解目的,我通常只使用 sprintf 来实现此目的。
It's not the same interface (so slightly different thinking), but if I understand the purpose correctly, I usually just use
sprintf
for this.