Search code examples
if-statementapplescriptcontain

AppleScript "if contain"


I have a script which look for the name and search for a match with a another variable.

It's working fine however if the variable 1 is "Name Demo" and variable 2 is "Demo Name" then the script don't find a match.

set nameMatchTXT to ""
if NameOnDevice contains theName then
    set nameMatch to theName & " : Name Match"
end if

Is there anyway to change this to find the match whatever the order ? PS the script is looking for word wild name, and sometime handle dual bit characters which can be a difficulty.


Solution

  • Your request stated:

    if the variable 1 is "Name Demo" and variable 2 is "Demo Name" then the script don't find a match.

    This will solve that problem:

    set var1 to "Name Demo"
    set var2 to "Demo Name"
    
    if (var2 contains (word 1 of var1)) and (var2 contains (word 2 of var1)) then
        -- you have a match
        display dialog "var1 and var2 match"
    else
        display dialog "no match"
    end if