Ruby Luva <noderat / hotmail.com> writes: > Hi all, > > I have a piece of data like so: > > aaaaaaa > bbbbbbb > ccccccc > 123 > ddddddd > yes > eeeeeee > > > I need to find the string yes and the string 123, however I first have > to find the string yes. I have this code to do this task: > > stack = "aaaaaaa > bbbbbbb > ccccccc > 123 > ddddddd > yes > eeeeeee" > > string = "yes" > stack.each do |c| > c.each {|line| > line.chomp!; > puts line.strip! if line.include? string} > end > > > How can I then, using 'yes' as my index to find the string '123'? > Basically I need to first find 'yes' and once discovered, search back to > find '123'. I hoep I explained it well enough. > > I have thought about using pop, to pop the values off from an array but > I am not sure how to do this. > > Could someone please give me a pointer to achieve this? Just do it. (stack = "aaaaaaa bbbbbbb 123 nay! ccccccc 123 yeah! ddddddd yes yes yes no eeeeeee") (string1 = "123") (string2 = "yes") (match1 = "") (match2 = "") (stack . each { |line| (line . chomp!) ((match1 = line) if (line . include? string1)) (if (line . include? string2) (match2 = line) (break) end)}) (printf "one=%s\ntwo=%s\n" , match1 , match2) one=123 yeah! two=yes yes -- __Pascal Bourguignon__