From: Thomas Worm Date: 2007-07-19T20:55:01+09:00 Subject: Re: identify and extract positions from a string - how to? On Thu, 19 Jul 2007 20:16:12 +0900, Marc Hoeppner wrote: > As it is now I have a file that contains coordinates and a second file > that contains the string that I want to extract from. > > So ideally the script would read each line of the coordinate file > > 45..78 > 90..120 > etc Those ..-things are called ranges, which, what wonder, are a class in ruby. Have a look at http://corelib.rubyonrails.org/ for the class Range. another way to express str[45..78] is str[45,78] or str.slice(45,78) or str.slice(45..78), where the numbers can be replaced by variables: str[fr..to], str[fr,to], str.slice[fr,to], str.slice(fr..to) This information can be found at the same webpage, just look for the class String ;-) > and uses it in the extraction method > > file.readlines each do |l| > puts string[l] > end > > Doesnt work tho -any suggestions on how to pipe each line of the > coordinate file to the string method? I know I know, probably simple, > but I am still learning ;) l is a String-object, not a Range-object. file.readlines each do |l| fr, to = l.split(/\.\./) puts string[fr,to] end should do the job. The thingy with the slashes in the split-method is a regular expression. Regards Thomas