How to compare two strings (case insensitive) in ColdFusion

CompareNoCase() - compare two strings (case insensitive)

CompareNoCase.cfm


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CompareNoCase function example: how to compare two strings (case insensitive)</title>
</head>

<body>
<h2 style="color:hotpink">CompareNoCase Function Example</h2>

<cfset String1="John">
<cfset String2="john">
<cfoutput>
<b>
String1: #String1#
<br />
String2: #String2#
</b>
<br />
</cfoutput>

<cfset StringCompareResult=CompareNoCase(String1,String2)>

Result:
<cfif StringCompareResult EQ 0>
 Two strings are equal
<cfelseif StringCompareResult LT 0>
 String1 is less than String2
<cfelse>   
 String1 is greater than String2
</cfif>

<br /><br />
<cfset String1="Ben">
<cfset String2="John">
<cfoutput>
<b>
String1: #String1#
<br />
String2: #String2#
</b>
<br />
</cfoutput>

<cfset StringCompareResult=CompareNoCase(String1,String2)>

Result:
<cfif StringCompareResult EQ 0>
 Two strings are equal
<cfelseif StringCompareResult LT 0>
 String1 is less than String2
<cfelse>   
 String1 is greater than String2
</cfif>

</body>
</html>


More ColdFusion examples