Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3432

Re: Can I split the array from text?

From Joey Zhou <yimutang@gmail.com>
Newsgroups comp.lang.ruby
Subject Re: Can I split the array from text?
Date 2011-04-24 08:21 -0500
Organization Service de news de lacave.net
Message-ID <6d8f6a42e814dec670357ff39a49eee6@ruby-forum.com> (permalink)
References <f49ba0d3c9809988b28fc4042f50998a@ruby-forum.com>

Show all headers | View raw


Maybe you can refer to Enumerable#slice_before

Here's a sample code:

a = ["Member","Friends","Hello","Components","Family","Lastname"]
b = a.slice_before {|elem| elem == "Components" }.to_a
p b[0] #=> ["Member", "Friends", "Hello"]
p b[1] #=> ["Components", "Family", "Lastname"]

Joey

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Can I split the array from text? Sira PS <ploy.sukachai@gmail.com> - 2011-04-24 03:02 -0500
  Re: Can I split the array from text? Joey Zhou <yimutang@gmail.com> - 2011-04-24 08:21 -0500
  Re: Can I split the array from text? Joey Zhou <yimutang@gmail.com> - 2011-04-24 08:35 -0500
    Re: Can I split the array from text? Roger Braun <roger@rogerbraun.net> - 2011-04-24 09:06 -0500
  Re: Can I split the array from text? Brian Candler <b.candler@pobox.com> - 2011-04-24 11:01 -0500

csiph-web