[ Date Index ][
Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday 10 July 2003 00:14, Neil Williams wrote: > What's the best way to compare two strings, each containing comma > separated values, to see if ANY of the values in the first string match > any of the values in the second string? for > e.g. > $string1 = "PHP, XML, GnuPG, standards, design"; > $string2 = "C++, Perl, PHP, networking, security"; > > So $string1 should give a match with $string2. Ok, this is not a very serious attempt - but... tony@xxxxxx:~> python Python 2.2.2 (#1, Mar 17 2003, 15:17:58) [GCC 3.3 20030226 (prerelease) (SuSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> string1="PHP,XML,GnuPG,standards,design" >>> string2="C++,Perl,PHP,networking,security" >>> s1 = string1.split(",") >>> s2 = string2.split(",") >>> for s in s1: ... if s in s2: print "Match on %s" % s ... Match on PHP >>> Tony - -- 404 Future not Found -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux) iD8DBQE/DKir+ZJrkBuz/nkRAl2HAJ9NjPpFeU+Cc50qxx8clz+KnIRGMACfSvrj 5/eMZqzinE3h5hv7KpEFIZk= =TL23 -----END PGP SIGNATURE----- -- The Mailing List for the Devon & Cornwall LUG Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the message body to unsubscribe.