Ruby 字符串格式 : Omit element in list

标签 ruby string-formatting

Ruby 让我可以:

    list = [1,2,3]
    puts "%s %s" % list

并返回 1 2。如果我想跳过第二个元素(打印 1 3)怎么办?是的,我知道没有字符串格式也很容易做到,但对于我的具体情况,我想知道是否可以使用字符串格式。

最佳答案

puts "%1$s %3$s" % list

........

关于Ruby 字符串格式 : Omit element in list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32999586/

相关文章:

ruby-on-rails - Jekyll 液体异常 : Cannot find/bin/sh on Windows

ruby - 规范测试基于 EventMachine 的(Reactor)代码

php - en_CA 语言环境中 sprintf 中的逗号作为小数点分隔符

python - 我试图在Python中运行一些代码,并得到错误“元组索引超出范围”。有人知道我在想什么吗?

c# - 已四舍五入的小负数的 StringFormat 问题

ruby - 弃用 : HTTParty will no longer override `response#nil?` . 这个弃用警告是什么意思?

ruby - 在 Ruby 中对哈希数组进行排序(按存在可选键+值排序)

pandas - IPython/pandas 中的格式问题

Python:将文本格式化为特定列

ruby - bundle 安装错误 - 你的 bundle 只支持平台 [] 但你的本地平台是 ["ruby", "x86_64-linux"]