Strings in AppleScript are a type of data stored by a variable that contain a simple line or lines of text.
Lets create two strings and set each one to a variable:
set string1 to "hello world"
set string2 to "HELLO WORLD"
To compare these two strings you can use the Equality operator =
:
string1 = string2
Result: true
I find the above approach the simplest coming from other scripting languages even though to compare strings you would sometimes use ==
. If you find this confusing you can use the English language based scripting style:
string1 is equal to string2
Result: true
you can use equals
in the Script Editor but once you hit the compile button, 🔨, it will replace equal
with is equal to
.
To use the inequality in AppleScript we will modify one of the two strings with a period:
set string1 to "hello world."
set string2 to "HELLO WORLD"
To be able to use the symbol not equal to ≠
is a cumbersome process but it can be achieved by holding down alt/option+=:
string1 ≠ string2
Result: true
If you find that a pain to remember there is also the English language style:
string1 is not string2
Result: true
If you type isn't
Script Editor on compile will convert the text to is not
but you can also type:
string1 doesn't equal string2
and the text doesn't equal
will convert to is not equal to