CountIt(str, c)
Last updated October 17, 2003
Version: 1 | Requires: ColdFusion 5 | Library: StrLib
Description:
Get a count on searching string in the searched string. Simular to ListLen, however this UDF accepts a string, not a single character, as a delimiter.
Return Values:
Returns a numeric value.
Example:
<CFOUTPUT>
STR=#STR#<BR>
CountIt(STR,"what a world") =
#CountIt(STR, "what a world")#<BR>
CountIt(STR,"world") =
#CountIt(STR, "world")#<BR>
CountIt(STR,"d") =
#CountIt(STR, "d")#<BR>
</CFOUTPUT>
Parameters:
| Name | Description | Required |
|---|---|---|
| str | The string to search. | Yes |
| c | The string to look for. | Yes |
Full UDF Source:
<cfscript>
/**
* Get a count on searching string in the searched string.
* Updated by Raymond Camden
*
* @param str The string to search. (Required)
* @param c The string to look for. (Required)
* @return Returns a numeric value.
* @author Peini Wu (pwu@hunter.com)
* @version 1, October 17, 2003
*/
function CountIt(str, c) {
var pos = findnocase(c, str, 1);
var count = 0;
if(c eq "") return 0;
while(pos neq 0){
count = count + 1;
pos = findnocase(c, str, pos+len(c));
}
return count;
}
</cfscript>
Search CFLib.org
Latest Additions
Tayo Akinmade added
arrayTrim
10 day(s) ago
Will Belden added
longTime
15 day(s) ago
James Sleeman added
quickSort
25 day(s) ago
Ben Forta added
GetHostAddress
28 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)