m2 has asked for the wisdom of the Perl Monks concerning the following question:
Hiyas :)
Here's the situation: I have many pairs of 2 strings that may (or may not) match each other from the beginning up to a certain point, then become different. What's the "best" (efficient, clean, etc) way of determining 1). the matching parts of the two strings 2). the part of each that's different?
i.e. for:
Regards,
m2.
i.e. for:
I want:$string1 = "the date is today"; $string2 = "the date is tomorrow";
It isn't hard to iterate over the first string letter by letter and do comparison to the second, but it really seems like there should be a more... elegant solution. Any ideas?$matchingpart = "the date is to" $diff1 = "day" $diff2 = "morrow"
Regards,
m2.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Matching bits of 2 strings
by japhy (Canon) on Jan 22, 2002 at 04:50 UTC | |
Re: Matching bits of 2 strings
by Fletch (Bishop) on Jan 22, 2002 at 07:31 UTC | |
by japhy (Canon) on Jan 22, 2002 at 22:34 UTC | |
Re: Matching bits of 2 strings
by Zaxo (Archbishop) on Jan 22, 2002 at 07:04 UTC | |
Re: Matching bits of 2 strings
by Anonymous Monk on Jan 22, 2002 at 13:49 UTC |
Back to
Seekers of Perl Wisdom