FindOccurrences(tString, tsubString)
Last updated March 20, 2002
Version: 3 | Requires: ColdFusion 5 | Library: StrLib
Description:
Returns the number of times a pattern exists within a string.
Return Values:
Returns the number of occurrences.
Example:
<CFOUTPUT>"is" occurs #FindOccurrences(TestString,"is")# times in TestString</CFOUTPUT>
Parameters:
| Name | Description | Required |
|---|---|---|
| tString | The string to check. | Yes |
| tsubString | The string to look for. | Yes |
Full UDF Source:
<cfscript>
/**
* Returns the number of times a pattern exists within a string.
* Modified by Raymond Camden
* Rewritten based on original UDF by Cory Aiken (corya@fusedsolutions.com)
*
* @param tString The string to check.
* @param tsubString The string to look for.
* @return Returns the number of occurrences.
* @author Shawn Seley (corya@fusedsolutions.comshawnse@aol.com)
* @version 3, March 20, 2002
*/
function FindOccurrences(tString,tsubString){
if(not len(tString) OR not len(tsubString)) return 0;
else {
// delete all occurences of tString
// and then calculate the number of occurences by comparing string sizes
return ((len(tString) - len(replaceNoCase(tString, tsubString, "", "ALL"))) / len(tsubString));
}
}
</cfscript>
Search CFLib.org
Latest Additions
Shawn Porter added
DeMoronize
3 hour(s) ago
Chris Carey added
readPropertiesFi...
1 day(s) ago
Randy Johnson added
lastDayofWeek
3 day(s) ago
Frank Marion added
sitemapPing
7 day(s) ago
Top Rated
QuickSort
Rated 5.0, 3 time(s)
indentXml
Rated 5.0, 3 time(s)
queryColumnsToSt...
Rated 5.0, 3 time(s)
generateSsccAsn
Rated 5.0, 3 time(s)