tomkinite
asked on
Limit Words
In CF, to limit characters is no big deal:
#left(query.column,100)#
but what if you wanted to limit characters but code it so it ends the current word. Example:
With a normal Left() function: "The cat crossed the road, got hit by a car and died. We took the anim..."
With an enhanced, custom function: "The cat crossed the road, got hit by a car and died. We took the animal..."
Is there a clean way of doing this? Essentially, what it must do is detect a space, and then end the text "preview".
Thanks for any help.
#left(query.column,100)#
but what if you wanted to limit characters but code it so it ends the current word. Example:
With a normal Left() function: "The cat crossed the road, got hit by a car and died. We took the anim..."
With an enhanced, custom function: "The cat crossed the road, got hit by a car and died. We took the animal..."
Is there a clean way of doing this? Essentially, what it must do is detect a space, and then end the text "preview".
Thanks for any help.
ASKER
This is great, although:
1. At times, if you put, say, 33 characters for a string length it will sometimes get the first letter of a word.
2. Can we throw a test in that function for the length? When a length entered exceeds the actual length I get a parameter error.
1. At times, if you put, say, 33 characters for a string length it will sometimes get the first letter of a word.
2. Can we throw a test in that function for the length? When a length entered exceeds the actual length I get a parameter error.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Good stuff. The power of RE. Is there a good guide for CF-level RE? I can never find a good one on the net.
I use the stuff from my CF advanced book
http://www.amazon.com/exec/obidos/tg/detail/-/0321127102/qid=1069103235/sr=8-1/ref=sr_8_1/104-2007007-7290338?v=glance&n=507846
Not sure about online tutorials though might through coldfusion regex at google and see what it spits back.
http://www.amazon.com/exec/obidos/tg/detail/-/0321127102/qid=1069103235/sr=8-1/ref=sr_8_1/104-2007007-7290338?v=glance&n=507846
Not sure about online tutorials though might through coldfusion regex at google and see what it spits back.
<cfargument name="varr" type="string" required="yes">
<cfargument name="length" type="numeric" required="yes">
<cfset reallength = refind("\b",varr,length)>
<cfset returnvalue=left(varr,real
<cfreturn returnvalue>
</cffunction>