><cfset myWords = "Here are a bunch of words in a string. I want the first
>six.">
><cfset newWords = "">
><cfloop from="1" to="6" index="ii">
>       <cfset newWords = newWords & listgetat(myWords,ii," ") & " ">
></cfloop>
><cfoutput>#newWords#</cfoutput>

hey sean...that's a nice way of handling it! my mind is so linear sometimes
that i tend to not think about looping unless it's obvious like when i'm
working with arrays and structures.

since i'm always looking at optimizing code, i started to play around with
both methods to get those 6 words. i found that it doesn't matter how long
your text is, if you only want the first 6 words, then both methods work
equally fast. (i went to cnn.com and filched a long article) but if you're
looking for more than 6 words, the overhead for the looping becomes quickly
apparent. for instance, at 200 words, the looping took 200 ms while the
other way took 70ms. 

however, the looping seems to be more accurate. when i specify 400, for
instance, the looping returns 399 words while the other way returns just
370. i'm not sure why that is (btw, i just took the resultant output and
did a word count on them in word) but you should  be aware of it.

...just thought it was interesting.... -emily
------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to