I want to test if a string contains either of two text items ("&" or " and "). I want the test to return True if the string contains either item and False if it does not. I am using this test to determine if the specified string (the name of person(s) entered into a form field) is the name of a single person or the name of a couple.
The problem: This code seems to randomly vacillate between returning True and False. I have tried testing the string directly, testing a variable reference to the string, checking different strings, and explicitly resetting the value of the tested variables before running the test.... BUT the returned boolean continues to be unpredictable.
What am I missing?? (If this is an issue from the limitations of AppleScript, I'm open to using JavaScript to check the string).
The code below should return True when the test is run on variable x and y but False when run on variable z (because the "and" of "Southerland" is not a standalone word).
set x to "John Jacob & Johanna Smith"
set y to "Kathy and Kurt Gallows"
set z to "Barbara Southerland"
set theName to x
set coupleIdentifiers to {"&", " and "}
if theName contains some text item of coupleIdentifiers then
set testIt to true
else
set testIt to false
end if
get testIt
Aucun commentaire:
Enregistrer un commentaire