Link to home
Start Free TrialLog in
Avatar of jturkington
jturkington

asked on

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
SOLUTION
Avatar of cyberdevil67
cyberdevil67

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of James Rodgers
James Rodgers
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>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
Avatar of Dain_Anderson
Dain_Anderson

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! :-)
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.
Avatar of jturkington

ASKER

How would you validate this with

<cfoutput>
#left(field,100)#<cfif len(field) GT 100> ...</cfif>
</cfoutput>
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
glad i could help

thanks for the points