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

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