Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2416
| 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 -- <bbxx789_05ss@yahoo.com> |
| 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> (permalink) |
| References | <BANLkTinMv0-L01+pwiiLc0Gruk+56B1GeQ@mail.gmail.com> |
| 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 | <BANLkTinMv0-L01+pwiiLc0Gruk+56B1GeQ@mail.gmail.com> |
| 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 |
Show key headers only | View raw
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/.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Find similar | Unroll thread
String#each_*slice* methods (like Enumerable#each_slice) "Aaron D. Gifford" <astounding@gmail.com> - 2011-04-06 12:52 -0500
Re: String#each_*slice* methods (like Enumerable#each_slice) Quintus <sutniuq@gmx.net> - 2011-04-06 13:42 -0500
Re: String#each_*slice* methods (like Enumerable#each_slice) "Aaron D. Gifford" <astounding@gmail.com> - 2011-04-06 13:49 -0500
Re: String#each_*slice* methods (like Enumerable#each_slice) "Aaron D. Gifford" <astounding@gmail.com> - 2011-04-06 14:09 -0500
Re: String#each_*slice* methods (like Enumerable#each_slice) 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-06 18:33 -0500
csiph-web