Forum: Ruby Re: help regarding extracting a particular value in a file

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
67bb4df2775f6a6b603347dce7119571?d=identicon&s=25 unknown (Guest)
on 2006-05-26 15:13
(Received via mailing list)
In that case, you can use this (I follow the convention that numbering
of
lines
and of entries starts with 0, but you can subtract 1 in the brackets, if
you
prefer starting at 1 in the function call):

-------------------------------
class String
def  extract_entry(which_line,which_entry)
data_array=IO.readlines(self)  # reads content of file into an Array (
each
entry = one line)
line=data_array[which_line].split(",")
return line[which_entry]
end
end

file_name="data_to_split.txt"
res=file_name.extract_entry(0,1)
p  'result is'
p res
This topic is locked and can not be replied to.