Forum: Ruby extract lines from text file and place in an array

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Roger R. (Guest)
on 2008-10-16 15:56
hi i was wondering if anyone cud help

i have this code to read from a text file

def readftxt"input.txt")


how could i adapt it so if multiple lines are entered it could place
each line in an array?

thanks for any help
Jesús Gabriel y Galán (Guest)
on 2008-10-16 16:12
(Received via mailing list)
On Thu, Oct 16, 2008 at 1:56 PM, Roger Reeks
<removed_email_address@domain.invalid> wrote:
> each line in an array?
Try IO#readlines:

=> "z|x|c|v|b|n\na|b|c|d|e|f\n1|699|3|4|5|6\nq|w|e|r|t|y\n"
irb(main):002:0> IO.readlines("test.csv")
=> ["z|x|c|v|b|n\n", "a|b|c|d|e|f\n", "1|699|3|4|5|6\n",

Note that the \n is part of each string.

This topic is locked and can not be replied to.