1

I am attempting to parse text from a <cfoutput query="...">. I am interested in finding the number of times every word in the text is displayed. For example:

"My name is Bob and I like to Bob".

should result in

Bob - 2
Name - 1
etc, etc, etc.

I take my <cfoutput> from a twitter RSS feed. Here is my code:

<blink>
  <cfset feedurl="http://twitter.com/statuses/user_timeline/47847839.rss" />
  <cftry>
    <cffeed source="#feedurl#" properties="feedmeta" query="feeditems" />
    <cfcatch></cfcatch> 
  </cftry> 
  <ol>
    <cfoutput query="feeditems">
      #content# #id# <br><br>
    </cfoutput>
  </ol>
</blink>

I output a pretty great ordered list, but I can't figure out for the life of me how to parse the content and list how many times each word is used.

Thanks for any help you can provide, I am new to these forums!

Peter Boughton
  • 110,170
  • 32
  • 120
  • 176

1 Answers1

4

You can find a solution here:

http://www.coldfusionjedi.com/index.cfm/2007/8/2/Counting-Word-Instances-in-a-String

Basically, split the string up using regex and then loop over the results. There are some darn good comments here as well.

Raymond Camden
  • 10,661
  • 3
  • 34
  • 68
  • 4
    something I've noticed lately is that people post answers that link to a blog post or an article somewhere. Over time links tend to break. It would be better to just post the content of the answer here so people searching for this problem in the future can find the solution without being disappointed by clicking on broken links. – Jayson Oct 14 '09 at 15:18
  • Good point. Next time, unless the answer is real long, I'll put both a link and the text. Of course, if it means a lot of formatting, it may not be worth the double duty entry. – Raymond Camden Oct 20 '09 at 01:57