CFLib.org – Common Function Library Project

Left2(string, length)

Last updated February 24, 2002

author

Jordan Clark

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Parameters are the same as left(). 0 Length returns no value. Negative lengths will return the the full string minus the specified number of characters from the right.

Return Values:
Returns a string.

Example:

<cfoutput>
left2( "CFlib.org", 0 ) = #left2( "CFlib.org", 0 )#<br>
left2( "CFlib.org", 2 ) = #left2( "CFlib.org", 2 )#<br>
left2( "CFlib.org", -3 ) = #left2( "CFlib.org", -3 )#<br>
</cfoutput>

Parameters:

Name Description Required
string The string to modify. Yes
length The length to use. Yes

Full UDF Source:

/**
 * Adds zero and negative support to the length parameter of left().
 * 
 * @param string 	 The string to modify. 
 * @param length 	 The length to use. 
 * @return Returns a string. 
 * @author Jordan Clark (JordanClark@Telus.net) 
 * @version 1, February 24, 2002 
 */
function left2( string, length )
{
  if( length GT 0 )
    return left( string, length );
  else if( length LT 0 )
    return left( string, len( string ) + length );
  else return "";
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson