# Re: help regarding extracting a particular value in a file

**URL:** <https://www.ruby-forum.com/t/re-help-regarding-extracting-a-particular-value-in-a-file/95282>\
**Category:** Ruby\
**Created:** [May 26, 2006, 3:13pm UTC](https://www.ruby-forum.com/t/re-help-regarding-extracting-a-particular-value-in-a-file/95282 "2006-05-26T15:13:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 26, 2006, 3:13pm UTC](https://www.ruby-forum.com/t/re-help-regarding-extracting-a-particular-value-in-a-file/95282/1 "2006-05-26T15:13:48Z")

</div>

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
