1

是否可以在 ruby​​ 中打印按时间顺序排列的字符串?喜欢excel的页眉A - Z,然后AA, AB, AC。这可能在红宝石中吗?谢谢!

4

2 回答 2

0

是的。尝试

string = 'A'
99.times { puts string.succ! }
于 2013-02-12T04:42:40.313 回答
-2
class Numeric
  Alph = ("A".."Z").to_a
  def alph
    s, q = "", self
    (q, r = (q - 1).divmod(26)) && s.prepend(Alph[r]) until q.zero?
    s
  end
end

[1, 2, 3].map(&:alph) # => ["A", "B", "C"]
[26, 27, 28].map(&:alph) # => ["Z", "AA", "AB"]
于 2013-02-12T05:47:13.450 回答