Whatever message this page gives is out now! Go check it out!

Compare

Last update:
May 18, 2026

Description

Performs a case sensitive comparison of two strings.

Returns

  • -1, if string1 is less than string2
  • 0, if string1 is equal to string2
  • 1, if string1 is greater than string2

Category

Function syntax

Compare(string1, string2)

See also

CompareNoCase, Find

Parameters

Parameter
Description
string1
A string or a variable that contains one
string2
A string or a variable that contains one

Usage

Compares the values of corresponding characters in string1 and string2.

Example

<cfscript>
    myString1="ColdFusion"
    myString2="Coldfusion"
    writeOutput(compare(myString1,myString2) & "<br/>") // Returns -1 as first string < second string
    myString3="ColdFusion"
    writeOutput(compare(myString1,myString3) & "<br/>") // Returns 0 as both strimgs are equal
    myString4="ColdFusion (2018 release)"
    writeOutput(compare(myString4,myString1)) // Returns 1 as first string > second string
</cfscript>
Output
-1

0

1

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page