CFLib.org – Common Function Library Project

replaceLast(string, substring1, substring2)

Last updated June 11, 2009

author

John Whish

Version: 0 | Requires: CF5 | Library: StrLib

Description:
Replaces the last occurrence of a substring in a string, with another string.

Return Values:
Returns a string.

Example:

<cfset mystring = "Monday, Tuesday, Wednesday, Thursday, Friday, Friday, Sunday" />
<cfoutput>
#replaceLast(mystring,"Friday","Saturday")#
</cfoutput>

Parameters:

Name Description Required
string List to parse. Yes
substring1 Substring to search for. Yes
substring2 String to use for a replacement. Yes

Full UDF Source:

/**
 * Replaces the last occurrence of a substring in a string
 * 
 * @param string 	 List to parse. (Required)
 * @param substring1 	 Substring to search for. (Required)
 * @param substring2 	 String to use for a replacement. (Required)
 * @return Returns a string. 
 * @author John Whish (john.whish@crisp-ebusiness.com) 
 * @version 0, June 11, 2009 
 */
function replaceLast(string, substring1, substring2) {
	return Reverse(Reverse(arguments.string).replaceFirst(Reverse(arguments.substring1),Reverse(arguments.substring2)));
}
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