"dogflower" contains "dog". Right?

In plain AppleScript if I type:


"dogflower" contains "dog"

and run it, the result is true.

So how come if I type the following:


set string1 to "dogflower"
set string2 to "dog"
string1 contains string2

and run it, the result is false?

It works correctly here as posted. Result = true. Are there any typos or environmental considerations in your original script?

Well that is strange. When I pasted the text from this post into a new script it worked. Then when I went back into the first script and re typed it manually, it also worked. I’m sure there were no typos because I used the original text to paste into this post.

I pasted the text from the original script into a new script and it came back with false. But when I pasted it into TextEdit as text only and then into a new script, it came back with true.

Update on this, I found the problem.

It happened when I captured a string by selecting a phone number in the Contacts app and using this to define a string variable in AppleScript. This happens the same whether I am editing the contact or not. Along with the copied phone number came a null character at the beginning and end of the string.

I isolated the problem down to where a test AppleScript was literally telling me that two variables which visually contained the same string value were not actually the same. I found out the reason by counting the characters in the string. One had more characters. After splitting the strings into lists of characters, “” was a member of the list.

It’s the strangest thing, I didn’t even know that it was possible for a string to contain a null character.