> -----Original Message-----
> From: Bobby Hartsfield [mailto:[EMAIL PROTECTED]
> Sent: Sunday, November 25, 2007 11:01 AM
> To: CF-Talk
> Subject: RE: looping through each row
> 
> <cfscript>
>       function charCount(str,char)
>       {
>               var i = 1;
>               var cnty = 0;
>               for (;i lte len(str); i=i+1)
>               {
>                       if (mid(lst, i, 1) is char)
>                       {
>                       cnty = cnty + 1;
>                       }
>               }
>               return cnty;
>       }
> </cfscript>

I like the idea of abstracting this into a function a lot (I loves me
functions) but using the same principle as the last message I posted (look
for the difference in length after you remove "char") should make this
simpler:

<cfscript>
function charCount(str,char) {

        return ( len(str) - len(replace(char, "", str)) )

};
</cfscript>

Basically all this is saying (I might have wrote the code wrong) is:

"Return the length of the string MINUS the length of string after I've
removed all of the characters."

Your function signature is the same so this change would be transparent if
you already implemented it.

> <cfset lst = "1,2,3,,5,,,,9,10" />
> 
> <cfoutput>#charCount(lst, ',')#</cfoutput>

Jim Davis


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion is delivering applications solutions at at top companies 
around the world in government.  Find out how and where now
http://www.adobe.com/cfusion/showcase/index.cfm?event=finder&productID=1522&loc=en_us

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293778
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to