Jump to content

Which function to use?


Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...