compare
Description
Performs a case sensitive comparison of two strings.
Categories
Related
Syntax
Compare(string1, string2)
Attributes
| Attribute | Description | Required | Default |
|---|---|---|---|
| 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
<h3>Compare Example</h3>
The compare function performs a <I>case-sensitive</I> comparison of two strings.</p>
<cfif IsDefined("FORM.string1")>
<cfset comparison = Compare(FORM.string1, FORM.string2)>
<!--- Switch on the variable to give various responses. --->
<cfswitch expression = #comparison#>
<cfcase value = "-1">
<h3>String 1 is less than String 2</h3>
<I>The strings are not equal</I>
</cfcase>
<cfcase value = "0">
<h3>String 1 is equal to String 2</h3>
<I>The strings are equal!</I>
</cfcase>
<cfcase value = "1">
<h3>String 1 is greater than String 2</h3>
<I>The strings are not equal</I>
</cfcase>
<cfdefaultcase>
<h3>This is the default case</h3>
</cfdefaultcase>
</cfswitch>
</cfif>
<form action = "compare.cfm" method="post">
String 1
<br><input type = "Text" name = "string1">
String 2
<br><input type = "Text" name = "string2">
<input type = "Submit" value = "Compare these Strings" name = "">
<input type = "RESET">
</form>