[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

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
0
jturkington
Asked:
jturkington
  • 4
  • 2
  • 2
  • +2
4 Solutions
 
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
 
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
mrichmonCommented:
#Left(field, Min(100, Len(field)))#<cfif Len(field) GT 100>...</cfif>
0
 
James RodgersWeb Applications DeveloperCommented:
glad i could help

thanks for the points
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now