----- Original Message ----- From: "Rob Anderson" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, September 04, 2003 3:30 PM Subject: Re: Extracting equal entities from two different sized arrays?
> > >""Freddy söderlund"" <[EMAIL PROTECTED]> wrote in > > message news:[EMAIL PROTECTED] > >Hi! > > > > Hi Hi again! Thanx for your time! Got time for an elaboration? > > >I have stuck my thoughts on this one, maybee someone can help me out? > > > >I have two arrays > > > >@array1 = "C:\Program files\directory1\directory2\directory3"; > >@array2 = "C:\Program files\directory1\dir2\dir3"; > > > > It looks like you're trying to build an array, each element of which is a > single character from your string. What you've actually got here is two > arrays both each holding a single string. > Another example on just how *stuck* I was! You're right ofcourse and I were wrong when typing my example. It's really two strings: $string1 and $string2. Let me re-phrase my question a bit: I want to compare the two strings and I want to extract those chars that are matching each other in the first and second string (in order from the beginning), and put them in a new string (not array as I mistakenly said earlier). So, if I have $string1 = "C:\Program files\directory1\directory2\directory3" $string2 = "C:\Program files\directory1\dir2\dir3" then I want the output to be $string3 = "C:\Program files\directory1\"; > >my @string_array = split('', "onetwothree"); > > this would build an array with an element for each character. However you > can quickly compare this strings in the way you want without resorting to > arrays. I've posted an answer to a similar question on this list here... > > http://groups.google.com/groups?q=Comparing+two+strings+for+first+difference > &ie=UTF-8&oe=UTF-8&hl=en > I gave you the wrong flightplan so your rockets didn't take me all the way to the moon. ;-) Your example works good but it can't give me the resulting 3:rd string. It only gives me the number of how many characters that matches. > Good luck > > > > >What I want to do is, compare the arrays, one char at a time, from the > beginning and stop when I find two >chars that are different, putting the > matching chars in a new scalar. > > > >Any suggestions? > > > >Greatfull for any help! > > > >/Freddy > > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]