IsPalindrome(string)
Last updated November 22, 2001
Version: 1 | Requires: CF5 | Library: StrLib
Description:
Checks string to see if it is a palindrome. A palindrome is any word or phrase that is the same spelled forwards or backwards. The test performed will ignore spaces and punctuation.
Return Values:
Returns a boolean.
Example:
<cfset mystr = "racecar">
<cfset complex = "Sums are not set as a test on Erasmus">
<cfset bad = "This will not work.">
<cfoutput>
Is "racecar" a Palindrome: #isPalindrome(mystr)#<BR>
Is "Sums are not set as a test on Erasmus" a Palindrome: #isPalindrome(complex)#<BR>
Is "This will not work." a Palindrome: #isPalindrome(bad)#<BR>
</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
string | The string to check. | Yes |
Full UDF Source:
/**
* Checks string to see if it is a pPalindrome.
* Modified by Raymond Camden
*
* @param string The string to check.
* @return Returns a boolean.
* @author Douglas Williams (klenzade@i-55.com)
* @version 1, November 22, 2001
*/
function isPalindrome(string) {
var newstring = rereplacenocase(string, '[^a-z1-9]','', 'ALL');
return newstring eq reverse(newstring);
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016