f



Is there a way to insert table rows into an array?

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
0
Troy
7/26/2016 10:07:50 AM
comp.lang.ruby 48886 articles. 0 followers. Post Follow

1 Replies
345 Views

Similar Articles

[PageSpeed] 0

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
0
WJ
7/27/2016 12:51:15 PM
Reply: