lastIndexOf(targetString, lastChar)
Last updated August 16, 2008
Version: 2 | Requires: CF6 | Library: StrLib
Description:
This UDF returns the index position of the last matching character in a string that you are searching for. If no matching string is found, a 0 is returned.
Return Values:
Returns a number.
Example:
<cfset file_name = "test.txt">
<cfset fileExtensionPosition = len(FORM.file_name) - lastIndexOf(FORM.file_name, ".")>
<!--- fileExtensionPosition = 4 --->
<cfset fileExt = "#removeChars(FORM.file_name, 1, fileExtensionPosition)#">
<!--- fileExt = .txt --->
Parameters:
Name | Description | Required |
---|---|---|
targetString | String to check. | Yes |
lastChar | Character to look for. | Yes |
Full UDF Source:
<!---
Returns the index position of the last matching character in a string.
v2 rewrite by Raymond Camden
@param targetString String to check. (Required)
@param lastChar Character to look for. (Required)
@return Returns a number.
@author Chris Douglas (chrisgdouglas@gmail.com)
@version 2, August 16, 2008
--->
<cffunction name="lastIndexOf" returntype="numeric" output="no">
<cfargument name="targetString" type="string" required="yes">
<cfargument name="lastChar" type="string" required="yes">
<cfif find(lastChar, arguments.targetString)>
<cfreturn len(arguments.targetString) - find(lastChar,reverse(arguments.targetString))>
<cfelse>
<cfreturn 0>
</cfif>
</cffunction>
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