Ruby - Convert Integer to String

前端 未结 7 1182
孤独总比滥情好
孤独总比滥情好 2021-01-17 11:28

In Ruby, trying to print out the individual elements of a String is giving me trouble. Instead of seeing each character, I\'m seeing their ASCII values instead:

<         


        
7条回答
  •  礼貌的吻别
    2021-01-17 11:49

    I think each_char or chars describes better what you want.

    irb(main):001:0> a = "0123"
    => "0123"
    irb(main):002:0> Array(a.each_char)
    => ["0", "1", "2", "3"]
    irb(main):003:0> puts Array(a.each_char)
    0
    1
    2
    3
    => nil
    

提交回复
热议问题