String#unpack が使える。
irb(main):001:0> "abc".unpack("A1A1A1") => ["a", "b", "c"] irb(main):002:0> "abcdefg".unpack("A1A2A3") => ["a", "bc", "def"] irb(main):003:0> "abcdefghij".unpack("A1A2A3A4") => ["a", "bc", "def", "ghij"]
まあ、Ruby ではこれが常套手段なのかな。
takatoh's blog – Learning programming languages.
String#unpack が使える。
irb(main):001:0> "abc".unpack("A1A1A1") => ["a", "b", "c"] irb(main):002:0> "abcdefg".unpack("A1A2A3") => ["a", "bc", "def"] irb(main):003:0> "abcdefghij".unpack("A1A2A3A4") => ["a", "bc", "def", "ghij"]
まあ、Ruby ではこれが常套手段なのかな。