Link to home
Start Free TrialLog in
Avatar of day6
day6Flag for United States of America

asked on

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)
Avatar of erikTsomik
erikTsomik
Flag of United States of America image

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
Avatar of day6

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America 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
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...
^^^ yep, what _agx_ said - switch the functions around.

Azadi
@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 ... ? :)
Avatar of day6

ASKER

since I already awarded points (my mistake for not seeing the original post) how do I change it after the fact?
Isn't there an option for "Request Assistance" or "Reallocate"?   (Sorry, I dont' ask questions on EE much.   So I'm not sure)