CFLib.org – Common Function Library Project

RFindNoCase(Substr, String[, Spos])

Last updated February 14, 2002

author

Charles Naumer

Version: 2 | Requires: CF5 | Library: StrLib

Description:
Returns the last index (case insensitive) of an occurrence of a substring in a string from a specified starting position. (The reverse of find.)

Return Values:
Returns the last position where a match is found, or 0 if no match is found.

Example:

<CFSET STR = "This is the test, the test of all tests.">
<CFSET STR2 = "Ray's World">
<CFOUTPUT>
Test: #RFindNoCase("t",STR)#<BR>
Test2: #RFindNoCase("T",STR)#<BR>
Test3: #RFindNoCase("/",STR2)#<BR>
</CFOUTPUT>

Parameters:

Name Description Required
Substr Substring to look for. Yes
String String to search. Yes
Spos Starting position. No

Full UDF Source:

/**
 * Returns the last index (case insensitive) of an occurrence of a substring in a string from a specified starting position.
 * Big update by Shawn Seley (shawnse@aol.com) -
 * UDF was not accepting third arg for start pos 
 * and was returning results off by one.
 * 
 * @param Substr 	 Substring to look for. 
 * @param String 	 String to search. 
 * @param Spos 	 Starting position. 
 * @return Returns the last position where a match is found, or 0 if no match is found. 
 * @author Charles Naumer (cmn@v-works.com) 
 * @version 2, February 14, 2002 
 */
function RFindNoCase(substr,str) {
  var rsubstr  = reverse(substr);
  var rstr     = "";
  var i        = len(str);
  var rcnt     = 0;

  if(arrayLen(arguments) gt 2 and arguments[3] gt 0 and arguments[3] lte len(str)) i = len(str) - arguments[3] + 1;

  rstr = reverse(Right(str, i));
  rcnt = findNoCase(rsubstr, rstr);

  if(not rcnt) return 0;
  return len(str)-rcnt-len(substr)+2;
}
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