开发者

Parsing text content in ColdFusion

开发者 https://www.devze.com 2022-12-08 10:36 出处:网络
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:

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>
  &l开发者_JS百科t;/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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消