From: Daniel N Date: 2007-03-28T10:07:57+09:00 Subject: Re: String Intersection. A better way ------=_Part_5132_24718123.1175044075922 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 3/28/07, Timothy Hunter wrote: > > Daniel N wrote: > > Hi all, > > > > I have an issue with strings. I want the intesection of two strings > > but I'm > > not sure how to go about it. I have two cases. > > > > Case 1: > > String 1 has the tail end intersecting with the start of string 2.. eg: > > > > String 1: The quick brown fox jumped over the lazy dog. > > String 2: fox jumped over the lazy dog. And in other news bla bla bla > > > > The problem is I don't know how much is intersecting. > > What I've done is to take string 1 and say psudo code > > > > until match found > > string2 =~ /^(value of string1)/ > > if match found set flag > > else delete first char of string1 > > loop again > > > > What is a better way to do this? > > > > Case 2: > > > > The start of String1 intersects with the end of string2 eg: > > > > String1: And here we are with another string. > > String2: bla bla bla. And here we are > > > > I don't really know about this one yet... I haven't gotten to it. > > > > Can anyone pls suggest what I might do? > > > > Thanx > > Daniel > > > Take a look at the MatchData class, particularly the #begin and #offset > methods. Thanx I didn't know about that one. But I still don't know how that will help me. Could you break it down for me pls? Thanx ------=_Part_5132_24718123.1175044075922--