Skip to main content
Inspiring
October 11, 2006
Answered

Find Charators in Memo field

  • October 11, 2006
  • 2 replies
  • 622 views
I have a memo type database field I'm Outputting. I need to find and count the total number of times the ">" charator appears.

How can I do this?
I need to count alot of others as well.. but if I figure how to do one i can do the rest.
Thanks!
    This topic has been closed for replies.
    Correct answer CRidgway
    There was a small limitation of the code I gave before so I created a better version. This version can still accept anything to count.

    You can pass a single value to count (">" etc...) or a list of values (">,this text,<b>, ,#chr(10)#" etc...). Spaces will be taken as literals (they are not stripped from the list elements).

    The script returns a count or camma seperated list of counts for the value(s) passed in the function.

    CR

    2 replies

    CRidgwayCorrect answer
    Inspiring
    October 11, 2006
    There was a small limitation of the code I gave before so I created a better version. This version can still accept anything to count.

    You can pass a single value to count (">" etc...) or a list of values (">,this text,<b>, ,#chr(10)#" etc...). Spaces will be taken as literals (they are not stripped from the list elements).

    The script returns a count or camma seperated list of counts for the value(s) passed in the function.

    CR

    Vbprog40Author
    Inspiring
    October 11, 2006
    Thank you! That worked great.
    Inspiring
    October 11, 2006
    The code below allows for single chars or anything you need. If you need to count commas, you will need to change the delimeter of charList to something that is not in the list and add the delimeter arguement to the cfloop.

    <cfset memoFieldName = "this is my@@@ field <b> it has ##a GT @sign in it!!!.">
    <cfset charList = "!,<,@,##,$,<b>,field">
    <cfoutput>
    <cfloop list="#charList#" index="x">
    <cfset charCount = val(len(memoFieldName) - len(replace(memoFieldName,x,"","all")))/Len(x)>
    Count of '#htmlEditFormat(x)#' = #charCount#<br>
    </cfloop>
    </cfoutput>

    Credit goes to http://www.cflib.org/udf.cfm?ID=961 for the original idea but the function did not work for some reason (I think it was a conflict with what was being passed to it). I also modified it to allow more then a single char to be counted.

    HTH,
    CR