Re: help regarding extracting a particular value in a file


#1

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