Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail From: 7stud -- Newsgroups: comp.lang.ruby Subject: Re: String#each_*slice* methods (like Enumerable#each_slice) Date: Wed, 6 Apr 2011 18:33:38 -0500 Organization: Service de news de lacave.net Lines: 26 Message-ID: <14aa0a86278a4755ef0050004fb530c9@ruby-forum.com> References: NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1302132849 55512 65.111.164.187 (6 Apr 2011 23:34:09 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Wed, 6 Apr 2011 23:34:09 +0000 (UTC) In-Reply-To: X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 381077 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: <14aa0a86278a4755ef0050004fb530c9@ruby-forum.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:2416 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/.