mattw112 Posted August 29, 2007 Share Posted August 29, 2007 Is there a function available that would do this: Compare 1 string to another string and let me know if ANY word in one string is also in the other string? So for example: String1 = "This is a string" String2 = "The dog is black" Both strings have "is" in common, so would like a TRUE returned. Or even an array of matching words?? Basically I want to compare various strings against a bunch of other strings and find ones that have similar words because those most likely would be a match. Another examples would be: String1 = "Microsoft Office" String2 = "Office 2007" These two would be a match on the word Office. Thanks, Terry Link to comment Share on other sites More sharing options...
Zedna Posted August 29, 2007 Share Posted August 29, 2007 Such function doesn't exists but you may make your own UDF. - StringSplit both strings with space as separator to get array of words - go through these arrays and compare them - make third output array with results based on previous comparison Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
tAKTelapis Posted August 29, 2007 Share Posted August 29, 2007 Hmm, good thinking Zedna.. A recursive search. Word 1 from array 1 compared to each word in array 2 Word 2 from array 1 compared to each word in array 2 and so forth. Should be reasonably simple. Link to comment Share on other sites More sharing options...
herewasplato Posted August 30, 2007 Share Posted August 30, 2007 Maybe http://www.autoitscript.com/forum/index.php?showtopic=12822 will help.-MSP- [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
tAKTelapis Posted August 30, 2007 Share Posted August 30, 2007 Geez, that code confuses me, i like this simplistic.. i also wanted something to kill a few minutes and make it look like i was working (code on your screen has the ability to do that, so this is what i came up with: (note: It will place doubles in the array.. so if your 2 sentences contain the same word twice, it will be added to the array twice) #include <Array.au3> $string1 = "This is a string" $string2 = "The dog is black" $test = _StringCompareWords($string1, $string2) _ArrayDisplay($test, "test") Func _StringCompareWords($scw_string1, $scw_string2) Dim $scw_wordarray[1] $scw_array1 = StringSplit($scw_string1, " ") $scw_array2 = StringSplit($scw_string2, " ") For $i = 1 to $scw_array1[0] For $x = 1 to $scw_array2[0] If $scw_array1[$i] = $scw_array2[$x] Then _ArrayAdd($scw_wordarray, $scw_array1[$i]) Else ContinueLoop EndIf Next Next Return $scw_wordarray EndFunc ;==> _StringCompareWords() Link to comment Share on other sites More sharing options...
mattw112 Posted August 30, 2007 Author Share Posted August 30, 2007 Thanks, that is very helpful! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now