I don't know if this will qualify as either neat or elegant, but I believe
that it will work.  If not, please forgive me, I haven't tested it
exhaustively ;)

<cfset partA = Left(test1,301)>
<cfif Right(partA,1) EQ " ">
        <cfset final = partA>
<cfelse>
        <cfset lastword = ListLast(partA," ")>
        <cfset final = Left(partA,Len(partA)-Len(lastword))>
</cfif>

Note: test1 is the string we are truncating, final is the result

Bob


-----Original Message-----
From: BORKMAN Lee [mailto:[EMAIL PROTECTED]]
Sent: Sunday, October 29, 2000 10:51 PM
To: CF-Talk
Subject: RE: Limit the output of words to 300 chars


Please Andrew.  Lay off the cheap sentimentality.  All this lovin' is
getting a little mushy.

btw, your solution will get rid of the last word in the 300 characters, even
if the word was complete, which may not be exactly what you want. Sometimes
basic is not so basic.

Take a look at char 301.  If it's whitespace, or maybe even punctuation, you
can leave your 300 chars alone.  And that's just the start of the fun.

Neatest, most elegant solution to this near-but-not-quite trivial problem
wins a beautiful set of steak knives.

Lee (Bjork) Borkman
http://bjork.net ColdFusion Tags by Bjork


-----Original Message-----
From: Scott, Andrew [mailto:[EMAIL PROTECTED]]

Easy do a left(string,300) then reverse the string and find the first space
get the position and then do a mid on that? Some of these quesations are
very basic programming skills guys!

regards
Andrew Scott

-----Original Message-----
From: Nathan Stanford [mailto:[EMAIL PROTECTED]]

How can I Limit the output of words to 300 chars but don't cut off a word in
the middle?


IMPORTANT NOTICE:
This e-mail and any attachment to it is intended only to be read or used by
the named addressee.  It is confidential and may contain legally privileged
information.  No confidentiality or privilege is waived or lost by any
mistaken transmission to you.  If you receive this e-mail in error, please
immediately delete it from your system and notify the sender.  You must not
disclose, copy or use any part of this e-mail if you are not the intended
recipient.  The RTA is not responsible for any unauthorised alterations to
this e-mail or attachment to it.
----------------------------------------------------------------------------
--------------------
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists or send a
message with 'unsubscribe' in the body to [EMAIL PROTECTED]

------------------------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists or send a message 
with 'unsubscribe' in the body to [EMAIL PROTECTED]

Reply via email to