differentChars(string [, caseSensitive])
Last updated February 6, 2004
Version: 1 | Requires: ColdFusion 5 | Library: StrLib
Description:
Counts how many different chars are in a string. Usable for passwords where you can ensure there is at least x different chars, can check case sensitive and not.
Return Values:
Returns a number.
Example:
<cfoutput>
Not case sensitive: #differentChars(mystring)#<br>
Case sensitive: #differentChars(mystring,true)#
</cfoutput>
Parameters:
| Name | Description | Required |
|---|---|---|
| string | String to check. | Yes |
| caseSensitive | Determines if case sensitivity is used. Defaults to false. | No |
Full UDF Source:
<cfscript>
/**
* Counts how many different chars are in a string.
* removed use of arguments. to make it cf5 compat
*
* @param string String to check. (Required)
* @param caseSensitive Determines if case sensitivity is used. Defaults to false. (Optional)
* @return Returns a number.
* @author Bjorn Jensen (public.cflib@saghian.com)
* @version 1, February 6, 2004
*/
function differentChars(string){
var iCount = 0;
var i = 0;
var sChars = "";
var sChar = "";
var caseSensitive = false;
if (arrayLen(arguments) eq 2 and isBoolean(arguments[2]) and arguments[2]) {
caseSensitive = true;
}
for(i=1;i lte len(string);i=i+1){
sChar = mid(string, i, 1);
if (caseSensitive and not find(sChar, sChars)){
sChars = sChars & sChar;
iCount = iCount+1;
} else if (not caseSensitive and not findNoCase(sChar, sChars)){
sChars = sChars & sChar;
iCount = iCount+1;
}
}
return iCount;
}
</cfscript>
Search CFLib.org
Latest Additions
Dave Anderson added
iniToStruct
20 day(s) ago
Dave Anderson added
deDupeArray
20 day(s) ago
Richard added
dice
22 day(s) ago
Isaac Dealey added
getRelative
a while ago
Top Rated
backupDatabase
Rated 5.0, 22 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)
highlightAndCrop
Rated 5.0, 4 time(s)