You are here: irt.org | FAQ | ColdFusion | Q3018 [ previous next ]
String1 = "myString"
String2 = "MyString"
To compare these two strings without case-sensitivity, we would just say:
<cfif string1 eq string2>....</cfif>
This CFIF would return a TRUE value, and execute the code between the CFIF tags.
However, to make the comparison case-sensitive, we can use the ColdFusion Compare() function.
<cfif Compare(string1,string2) eq "0">...</cfif>
In this case, the two strings are not the same and will not execute the code between the CFIF tags.
The Compare() function performs a check on the ASCII values of the characters in each string. The function returns a negative number if string1 is less than string2, zero(0) if string1 is equal to string2, or a positive number if string1 is greater than string2.