CFLib.org – Common Function Library Project

HighlightFromTo(str, start, end[, startHi][, endHi])

Last updated September 24, 2002

author

Scott Delatush

Version: 2 | Requires: CF5 | Library: StrLib

Description:
Applies a simple highlight from and to a given position in a string. Works well to quickly reference certain position of characters in large strings.

Return Values:
Returns a string.

Example:

<cfoutput>
#highLightFromTo("1234567890",5,8)#<br>
</cfoutput>

Parameters:

Name Description Required
str String to modify. Yes
start Position to insert highlight. Yes
end Position to end highlight. Yes
startHi String to use for the beginning of the highlight. Defaults to <span style="background-color: yellow;"> No
endHi String to use for the end of the highlight. Defaults to </span> No

Full UDF Source:

/**
 * Applies a simple highlight from and to a given position in a string.
 * version 2 by rcmamden
 * 
 * @param str 	 String to modify. (Required)
 * @param start 	 Position to insert highlight. (Required)
 * @param end 	 Position to end highlight. (Required)
 * @param startHi 	 String to use for the beginning of the highlight. Defaults to <span style="background-color: yellow;"> (Optional)
 * @param endHi 	 String to use for the end of the highlight. Defaults to </span> (Optional)
 * @return Returns a string. 
 * @author Scott Delatush (delatush@yahoo.com) 
 * @version 2, September 24, 2002 
 */
function HighLightFromTo(str,start, end) {
	var startHi = "<span style=""background-color: yellow;"">";
	var endHi = "</span>";

	if(arrayLen(arguments) gte 4) startHi = arguments[4];
	if(arrayLen(arguments) gte 5) endHi = arguments[5];

	if(start gte (len(str) - 1)) return str;
	if(end gte len(str)) end = len(str);

	str = insert(startHi,str,start-1);
	str = insert(endHi,str,end+len(startHi));
	return str;
}
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