?
Solved

Cold Fusion String Function LEFT placement?

Posted on 2010-01-12
10
Medium Priority
?
893 Views
Last Modified: 2012-05-08
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
Comment
Question by:day6
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 26293852
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
 
LVL 19

Expert Comment

by:erikTsomik
ID: 26293878
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 26294011
0
Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

 
LVL 1

Author Comment

by:day6
ID: 26296882
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
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 26300104
Try reversing the functions

#ParagraphFormat(abbreviate(description,150))#
0
 
LVL 52

Expert Comment

by:_agx_
ID: 26300195
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
 
LVL 27

Expert Comment

by:azadisaryev
ID: 26300883
^^^ yep, what _agx_ said - switch the functions around.

Azadi
0
 
LVL 52

Expert Comment

by:_agx_
ID: 26307248
@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
 
LVL 1

Author Comment

by:day6
ID: 26307527
since I already awarded points (my mistake for not seeing the original post) how do I change it after the fact?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 26307887
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question