Thanks everyone. Lots of great ideas and links.
In the end I looked at some UDF examples of similar functions and then wrote my own very simple UDF:
<cfscript>
function countChar(srchString, srchVal) {
var charCount=0;
var strLen=len(srchString);
for (idx=1; idx LTE strLen; idx=idx+1) {
if (mid(srchString, idx, 1) eq srchVal) {
charCount = charCount + 1;
}
}
return charCount;
}
</cfscript>Thanks again,
Brett B)
Aaron DC wrote:
This would work great if CF treated contiguous delimiters (ie empty items) as list elements. Your example will fail for things like
ListLen("hello dolly", "l").
Was an explanation ever provided by Allaire as to why empty items are ignored?
Aaron
----- Original Message ----- From: "TRACEY, Darren" <[EMAIL PROTECTED]> To: "CFAussie Mailing List" <[EMAIL PROTECTED]> Sent: Thursday, July 08, 2004 9:54 AM Subject: [cfaussie] RE: Count occurances of a character in a string
How about this: listLen(originalString,characterToCount)-1 No special non standard functions to get. Just bog standard cf tags/functions.
--- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] Aussie Macromedia Developers: http://lists.daemon.com.au/
-- Brett Payne-Rhodes Eaglehawk Computing t: +61 (0)8 9371-0471 f: +61 (0)8 9371-0470 m: +61 (0)414 371 047 e: [EMAIL PROTECTED] w: www.ehc.net.au
--- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] Aussie Macromedia Developers: http://lists.daemon.com.au/
