How do I...?

Compare Two Strings

String comparisons are performed in the same manor as number comparisons. As an example, we will create two strings, and perform an action based on their contents:

  1. Create two variables containing strings:

String1 = "I am String1";
String2 = "I am String2";

  1. Compare the two strings:

if String1 == String2 then
    --the two strings are equal
else
    --the two strings are not equal
    if String1 > String2 then
        --String1 is alphabetically larger than String2
    elseif String1 < String2 then
        --String1 is alphabetically smaller than String2
    end
end

Note: if you want to compare the lengths of two strings, you must use the String.Length action:

if String.Length(String1) == String.Length(String2) then
    --the two strings are the same length!!
end

Tip: To perform a non-case-sensitive comparison on two strings, use a String.CompareNoCase action.