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 "";
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson