This is a function I use. You can take out the "..." part if not needed.

        <cffunction name="trimLength" output="FALSE" 
                hint="Returns a string trimmed to the specified length plus 
...">
                <cfargument name="val" required="FALSE" default="" hint="string 
to trim">
                <cfargument name="len" required="FALSE" default="0" 
hint="length to trim string">
                <cfset var lst = 0>
                <cfif len(ARGUMENTS.val) LE ARGUMENTS.len>
                        <cfreturn ARGUMENTS.val>
                <cfelse>
                        <cfset lst = find(" ",ARGUMENTS.val,ARGUMENTS.len)>
                        <cfif lst IS 0>
                                <cfset lst = ARGUMENTS.len>
                        </cfif>
                        <cfreturn "#left(ARGUMENTS.val,lst)# ...">
                </cfif>
                
                <cfreturn ARGUMENTS.val>
        </cffunction>

-Brett

________________________________________
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Colin Wilson
Sent: Thursday, January 25, 2007 11:43 AM
To: 'Dallas/Fort Worth ColdFusion User Group Mailing List'
Subject: [DFW CFUG] trimming a string to so many words

Looking for a suggested resource where I might find how to trim a string to a 
certain length, but not chop the words..
 
such that it would be say 250characters, but then go back to the last space. 
 
I was thinking of just a rtrim, but wasn't sure if there was a better way?
 
Thanks
 
Colin

_______________________________________________
Reply to DFWCFUG:
  [email protected]
Subscribe/Unsubscribe:
  http://lists1.safesecureweb.com/mailman/listinfo/list
List Archives:
    http://www.mail-archive.com/list%40list.dfwcfug.org/
  http://www.mail-archive.com/list%40dfwcfug.org/
DFWCFUG Sponsors:
  www.HostMySite.com
  www.teksystems.com/

Reply via email to