CFLib.org – Common Function Library Project

FullLeft(str, count)

Last updated April 16, 2002
Download UDF

author

Marc Esher                                        Marc Esher

Version: 2 | Requires: ColdFusion 5 | Library: StrLib

 
Rated 17 time(s). Average Rating: 1.0

Description:
An enhanced version of left() that doesn't cut words off in the middle; instead, it searches backward until it finds a full word.

Return Values:
Returns a string.

Example:

<cfset text="You wouldn't see words chopped in half on the front page of the New York Times">

<cfoutput>
Full String: #text#<BR>
FullLeft(text, 25): #fullLeft(text, 25)#<BR>
FullLeft(text, 34): #fullLeft(text, 34)#<BR>
</cfoutput>

Parameters:

Name Description Required
str String to be checked. Yes
count Number of characters from the left to return. Yes

Full UDF Source:

<cfscript>
/**
* An enhanced version of left() that doesn't cut words off in the middle.
* Minor edits by Rob Brooks-Bilson (rbils@amkor.com) and Raymond Camden (rbils@amkor.comray@camdenfamily.com)
*
* Updates for version 2 include fixes where count was very short, and when count+1 was a space. Done by RCamden.
*
* @param str      String to be checked.
* @param count      Number of characters from the left to return.
* @return Returns a string.
* @author Marc Esher (rbils@amkor.comray@camdenfamily.comjonnycattt@aol.com)
* @version 2, April 16, 2002
*/

function fullLeft(str, count) {
    if (not refind("[[:space:]]", str) or (count gte len(str)))
        return Left(str, count);
    else if(reFind("[[:space:]]",mid(str,count+1,1))) {
         return left(str,count);
    } else {
        if(count-refind("[[:space:]]", reverse(mid(str,1,count)))) return Left(str, (count-refind("[[:space:]]", reverse(mid(str,1,count)))));
        else return(left(str,1));
    }
}
</cfscript>

Search CFLib.org


Latest Additions

John Bartlett John Bartlett added
browserDetect
4 day(s) ago

Rob Brooks-Bilson Rob Brooks-Bilson added
listCompare
7 day(s) ago

Stephen Withington Stephen Withington added
formToNameValueP...
15 day(s) ago

anthony petruzzi anthony petruzzi added
parseExcel
20 day(s) ago

Pablo Varando Pablo Varando added
returnRandomHEXC...
21 day(s) ago

Top Rated

Nathan Dintenfass                                 QueryStringChang...
Rated 5.0, 10 time(s)

Stephen Withington formToNameValueP...
Rated 5.0, 5 time(s)

Gyrus                                             HTMLSafe
Rated 5.0, 4 time(s)

Shlomy Gantz                                      viewCSS
Rated 5.0, 4 time(s)

Michael Sharman generateRandomKe...
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson