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 No
endHi String to use for the end of the highlight. Defaults to 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;
}

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