Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #7281 > unrolled thread
| Started by | Troy <remyamv@gmail.com> |
|---|---|
| First post | 2016-07-26 03:07 -0700 |
| Last post | 2016-07-27 12:51 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.ruby
Is there a way to insert table rows into an array? Troy <remyamv@gmail.com> - 2016-07-26 03:07 -0700
Re: Is there a way to insert table rows into an array? "WJ" <w_a_x_man@yahoo.com> - 2016-07-27 12:51 +0000
| From | Troy <remyamv@gmail.com> |
|---|---|
| Date | 2016-07-26 03:07 -0700 |
| Subject | Is there a way to insert table rows into an array? |
| Message-ID | <0f796612-2d59-4b70-832d-8214ac73ad81@googlegroups.com> |
Hey All,
I have a table with a few rows like the below
No. Name Emp id
1 John 123383
2 Bob 389736
3 Danny 932303
4 Joy 832652
Is there a way to insert the table rows into an array in Ruby which should look like:
ArrTable= ["1","John","123383"
"2","Bob","389736"
"3","Danny","932303"
"4","Joy","832652" ]
Thanks
[toc] | [next] | [standalone]
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Date | 2016-07-27 12:51 +0000 |
| Message-ID | <nnaao2$8fl$1@dont-email.me> |
| In reply to | #7281 |
Troy wrote:
> I have a table with a few rows like the below
>
> No. Name Emp id
> 1 John 123383
> 2 Bob 389736
> 3 Danny 932303
> 4 Joy 832652
>
> Is there a way to insert the table rows into an array
> in Ruby which should look like:
>
> ArrTable= ["1","John","123383"
> "2","Bob","389736"
> "3","Danny","932303"
> "4","Joy","832652" ]
>
s = "
No. Name Emp id
1 John 123383
2 Bob 389736
3 Danny 932303
4 Joy 832652"
s.strip.lines.drop(1).map(&:split)
==>[["1", "John", "123383"], ["2", "Bob", "389736"], ["3", "Danny",
"932303"], ["4", "Joy", "832652"]]
require 'pp'
==>true
pp s.strip.lines.drop(1).map(&:split)
[["1", "John", "123383"],
["2", "Bob", "389736"],
["3", "Danny", "932303"],
["4", "Joy", "832652"]]
--
Amazon bans book. After nearly a month on the site, all traces of the book and
its 80 reviews have been removed.
http://jamesfetzer.blogspot.com/2015/11/debunking-sandy-hook-debunkers-5.html
https://www.youtube.com/watch?v=EEl_1HWFRfo
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.ruby
csiph-web