From: 7stud -- Date: 2011-04-07T08:33:38+09:00 Subject: Re: String#each_*slice* methods (like Enumerable#each_slice) Aaron D. Gifford wrote in post #991274: > Hi, > > I find I periodically need to iterate over slices of a string. > Enumerable has the useful each_slice method, but in Ruby 1.9, I don't > see an equivalent for the String class. > How about: str = "hello world" while str.size > 0 substr = str.slice!(0, 3) #(offset, length) puts "-->#{substr}<--" end --output:-- -->hel<-- -->lo <-- -->wor<-- -->ld<-- -- Posted via http://www.ruby-forum.com/.