• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 905
  • Last Modified:

Cold Fusion String Function LEFT placement?

I'm trying to use the LEFT(string,count) function in Cold Fusion to concatenate a longtext MySQL display on a page. However, I do not like the variable results because I set a specific character count versus it concatenating at a paragraph break or end of a sentence.

ie: If I have a longtext database field that is 500 characters long and includes paragraph breaks and I only have room on my page to display 75 characters (for design purposes) before I create a link to display the remainder of the text (e.g. <read more>), I want the break of the character to not be mid word or mid-sentence BUT also not to exceed the 75 characters. In other words, I want it to stop at the end of a sentence BEFORE 75 characters.

Because every record has variable characters, i can't simply do a specific character search other than a period with a space following it.

I need the best (least) code to have it analyze the database field results and stop the display per the above.

My current code is:

#Left(ParagraphFormat(description),75)#... <a href="link">&lt:read more&gt;</a>

which produces broken words with the ellipses following (which is okay)
0
day6
Asked:
day6
  • 4
  • 2
  • 2
  • +1
1 Solution
 
erikTsomikSystem Architect, CF programmer Commented:
you can try counting words and display the only one that you need . read thishttp://www.coldfusionjedi.com/index.cfm/2007/8/2/Counting-Word-Instances-in-a-String
0
 
erikTsomikSystem Architect, CF programmer Commented:
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
day6Author Commented:
azadisaryev:

The "abbreviate" UDF works... except it gets rid of my PARAGRAPHFORMAT function... which i need.

My code is:

#abbreviate(ParagraphFormat(description),150)#

It displays properly without breaking any words, but it ignores the database carriage returns... which I want. Any ideas?
0
 
_agx_Commented:
Try reversing the functions

#ParagraphFormat(abbreviate(description,150))#
0
 
_agx_Commented:
BTW: The reason it didn't work is that the udf abbreviate() removes html tags.  So when you call it _after_ ParagraphFormat(), it removes the <p> tags that ParagraphFormat() just added...
0
 
azadisaryevCommented:
^^^ yep, what _agx_ said - switch the functions around.

Azadi
0
 
_agx_Commented:
@day6

Thanks for the points. But in all fairness - Azadi was the one who suggested the UDF in the first place.  It seems fair that he get some of the points ... ? :)
0
 
day6Author Commented:
since I already awarded points (my mistake for not seeing the original post) how do I change it after the fact?
0
 
_agx_Commented:
Isn't there an option for "Request Assistance" or "Reallocate"?   (Sorry, I dont' ask questions on EE much.   So I'm not sure)
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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