CompareIgnoreWhiteSpace(string1, string2 [, isCompareCaseSensitive])
Last updated December 2, 2008
Version: 1 | Requires: ColdFusion 5 | Library: StrLib
Description:
Performs a comparison of two strings ignoring any whitespace characters including form feeds, line feeds, carriage returns, tabs, vertical tabs, and spaces. Comparison is case sensitive unless a third argument of "false" is passed in.
Return Values:
Returns a boolean.
Example:
<cfset str2 = "The quick brown fox jumps over the lazy dog.">
<cfset strChange = CompareIgnoreWhiteSpace(str1,str2)>
<cfif strChange eq 0>
The strings are equal!
<cfelse>
The strings are NOT equal!
</cfif>
Parameters:
| Name | Description | Required |
|---|---|---|
| string1 | First string to compare. | Yes |
| string2 | Second string to compare. | Yes |
| isCompareCaseSensitive | Determines if the comparison should check case. Default is true. | No |
Full UDF Source:
<cfscript>
/**
* Performs a comparison of two strings ignoring any whitespace characters.
*
* @param string1 First string to compare. (Required)
* @param string2 Second string to compare. (Required)
* @param isCompareCaseSensitive Determines if the comparison should check case. Default is true. (Optional)
* @return Returns a boolean.
* @author Mark G. Smith (mark.g.smith@baesystems.com)
* @version 1, December 2, 2008
*/
function CompareIgnoreWhiteSpace(string1,string2) {
var string1NoWhiteSpace = REReplace(string1,"[\s]","","ALL");
var string2NoWhiteSpace = REReplace(string2,"[\s]","","ALL");
var isCompareCaseSensitive = true;
if(arrayLen(arguments) gte 3) isCompareCaseSensitive = arguments[3];
if (isCompareCaseSensitive)
return Compare(string1NoWhiteSpace, string2NoWhiteSpace);
else
return CompareNoCase(string1NoWhiteSpace, string2NoWhiteSpace);
}
</cfscript>
Search CFLib.org
Latest Additions
Tayo Akinmade added
arrayTrim
11 day(s) ago
Will Belden added
longTime
17 day(s) ago
James Sleeman added
quickSort
27 day(s) ago
Ben Forta added
GetHostAddress
30 day(s) ago
Top Rated
EksporSQLData
Rated 5.0, 16 time(s)
backupDatabase
Rated 5.0, 13 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)