compareNoCase
Description
Performs a case-insensitive comparison of two strings.
Categories
Related
Syntax
CompareNoCase(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 |
Returns
An indicator
of the difference:
A negative number, if string1 is
less than string2
0, if string1 is equal to string2
A positive number, if string1 is greater than string2
Example
<H3>CompareNoCase Example</H3>
This function performs a <I>case-insensitive</I> comparison of two strings.
<cfif IsDefined("form.string1")>
<cfset comparison = Comparenocase(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="comparenocase.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>