ColdFusion Programming/Listing the words from a block of text
Expert: Donald Hammond - 9/17/2010
QuestionI have to create an application, whereby a user enters a paragraph of text, and what is returned is a list of words from the paragraph and how many times it appears in the paragraph. It is not case-sensitive and the grammar doesn't matter either.
How would I go about creating this? So far the only idea I have got is to use structures, but I have no real clue on how to go about doing this. Any help would be really appreciated
AnswerAloha,
You have the right idea. Basically for this type of problem you need to think how you would do it with a pen and paper. More than likely you would start at the beginning and list unique words. When you hit a non-unique word you would put a mark next to it on your paper. Then count up how many marks you have (plus the original word).
Same thing here. Just treat the paragraph as a list with space as the delimiter and loop over it. Make a structure like
mywords.the = mywords.the+1
Then just print out the structure. You would first do a ifkeyexists to see if it is already there or not.