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

String functions

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

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy