Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #3439
| From | Brian Candler <b.candler@pobox.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: Can I split the array from text? |
| Date | 2011-04-24 11:01 -0500 |
| Organization | Service de news de lacave.net |
| Message-ID | <9d7348e487437e591621461c32a68b1e@ruby-forum.com> (permalink) |
| References | <f49ba0d3c9809988b28fc4042f50998a@ruby-forum.com> |
Sira PS wrote in post #994712:
> If I have an array like this
>
> ["Member", "Friends", "Hello", "Components", "Family", "Lastname"]
>
> And I need to split this array from "Components" and get 2 arrays which
> are
>
> ["Member", "Friends", "Hello"]
>
> and
>
> ["Family", "Lastname"]
>
> Can I do that and how?
I think this is the simplest way:
a = ["Member", "Friends", "Hello", "Components", "Family", "Lastname"]
i = a.index("Components")
p a[0...i]
p a[i+1..-1]
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Previous in thread | Find similar | Unroll 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