Displaying First N characters on Output

I have a table where i want to cfoutput query a number of fields from a database

I have a one field that can have quite a long description and would just like to display the first 100 characters and then cut it off with a couple of ..

Example
FieldID               Description                                      Field3
   1                    a long description lots of text...          etc..

How would i go about accomplishing this ?!


Cheers

JT
jturkingtonAsked:
Who is Participating?
 
mrichmonCommented:
#Left(field, Min(100, Len(field)))#<cfif Len(field) GT 100>...</cfif>
0
 
cyberdevil67Commented:
Hi jturkington,
 <cfoutput>#Left(string,100)#</cfoutput>

Cheers!
0
 
James RodgersWeb Applications DeveloperCommented:
or this

<cfoutput>
#left(field,100)#<cfif len(field) GT 100> ...</cfif>
</cfoutput>
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
James RodgersWeb Applications DeveloperCommented:
or if you are outputting the text into a fixed sized object, div, td etc., you can use teh text over-flow css attribute, but it is IE(6) only

see here
http://www.blakems.com/archives/000077.html
this is a great site
http://www.blooberry.com/indexdot/css/properties/position/textoverflow.htm

0
 
Dain_AndersonCommented:
All of these answers are correct, but consider this that simply using Left() will "chop" your words off in the middle of the word. I would recommend using a UDF:

http://www.cflib.org/udf.cfm?ID=329

This UDF will search backwords until it finds a full word:

#FullLeft(myText, 100)#

-Dain
0
 
James RodgersWeb Applications DeveloperCommented:
>>All of these answers are correct, but consider this that simply using Left() will "chop" your words off in the middle of the word. I would recommend using a UDF:

the way we do it for our 'news' headlines is up to the first .

left(string,find(". ",string))  <<-- notice the space after the . , prevents cut off of $10.36, looks for the first full stop.

no problems as of yet
0
 
Dain_AndersonCommented:
Yeah, that works if you need to stop at a full sentence or need to avoid chopping dollar values -- definitely a plus in many situations. We use the FullLeft() in areas where we need a "blurb" that could potentially lead to a very long page. The common denominator is that either method prevents "chopping," which I personally can't stand! :-)
0
 
mrichmonCommented:
Also another thing to consider is that if your string is LESS than 100 you could get an error so be careful that whichever method you use accounts for the actual length of the string for shorter strings.
0
 
jturkingtonAuthor Commented:
How would you validate this with

<cfoutput>
#left(field,100)#<cfif len(field) GT 100> ...</cfif>
</cfoutput>
0
 
James RodgersWeb Applications DeveloperCommented:
glad i could help

thanks for the points
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.