CFLib.org – Common Function Library Project

listAppendAndReplace(list1, list2, length[, delimiters])

Last updated August 10, 2007

author

Kit Brandner

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Appends one list to another, with a maximum list length specified, and replaces any overlapping values.

Return Values:
Returns a string.

Example:

#ListAppendAndReplace("192.168.0", "15.20", 4, ".")# would return 192.168.15.20

Parameters:

Name Description Required
list1 The original list. Yes
list2 The list to append. Yes
length The max list length allowed for the new list. Yes
delimiters List delimiters. Defaults to a comma. No

Full UDF Source:

/**
 * Appends one list to another, with a maximum list length specified, and replaces any overlapping values.
 * 
 * @param list1      The original list. (Required)
 * @param list2      The list to append. (Required)
 * @param length      The max list length allowed for the new list. (Required)
 * @param delimiters      List delimiters. Defaults to a comma. (Optional)
 * @return Returns a string. 
 * @author Kit Brandner (kit.brandner@serebra.com) 
 * @version 1, August 10, 2007 
 */
function listAppendAndReplace( list1, list2, length) {
    var delimiters = ",";
    var pos = length;
    var returnList = list1;
    if (arguments.length ge 4 and len(trim(arguments[4])) gt 0) delimiters = trim(arguments[4]);
    for ( ; pos ge (length - listLen(list2, delimiters)) ; pos = pos - 1) {
        if (listLen(list1, delimiters) gt pos)    returnList = listDeleteAt(returnList, pos + 1, delimiters);
    }
    if (left(list2, 1) eq delimiters) list2 = right(list2, len(list2) - 1);
    returnList = trim(returnList) & iif(right(returnList, 1) neq delimiters and (len(trim(list2)) gt 0 and len(trim(returnList)) gt 0), de(delimiters), de("")) & trim(list2);
    return returnList;
}

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