For a long time now I have used the "fullLeft()" udf, which works just fine and does exactly what it should. But the other day, I got a wild hair and, rather than calling in the fullLeft function to my page, decided to script something right in place... just 'because'.
And whaddyaknow, it works... works great, really.
But it is so simple - what am I missing?
Like most things, my 'aha' is haunted by a 'what if', as in 'what if it breaks on certain characters or other stuff in the text'? What if I don't really know what the heck I am doing? But ...hey... it works!
//// Here is the logic:
take a chunk of text and a number, passed in as variables.
replace all line breaks in the text with <br> tags (easy to remove if not needed)
if the length of the text is more than the given number, cut it off at that
number of characters
find the number of characters at the end of the remaining string that come after the last space ( ' '), and remove them
/// Here is the code:
* Another version of "full left"
* @param trimlength Length, in characters, to trim text to (Required)
* @param rawtext Text to trim (Required)
* @return Returns a string with an ellipsis (...)
* @author Michael Evangelista (mredesign.com)
* @created June 6, 2008
function trimtext(rawtext, trimlength)
// this line replaced line returns in the text block with html breaks
rawtext = replace(rawtext, chr(13), '<br />', 'all');
if (len(rawtext) gt trimlength)
cuttext = left(rawtext, trimlength);
trimlen = len(cuttext) - len(listLast(cutText, ' '));
texttouse = left(rawtext, trimlen) & '... <em>(<a class="morelink" href="##">more</a>)</em>';
texttouse = rawtext;
textoutput = '<p>' & texttouse & '</p>';
Feedback and/or testing appreciated.