ColdFusion UDF Library - listFill
December 16th, 2008
«« Back to ColdFusion Library
Category:
LIST
Description:
Returns a list with fillChar in place of any empty element in the list.
Parameters:
Returns:
(List)
Requires:
Sample Use:
listFill("item1,item2,,,item3","-");
Returns: item1,item2,-,-,item3
Copy to Clipboard
Category:
LIST
Description:
Returns a list with fillChar in place of any empty element in the list.
Parameters:
- list (List, required)
The list to perform the operation on. - fillChar (String, Default: (space))
The character to place in empty list items. - delimeter (String, Default: ,)
The delimiter to use for the list. - verbose (String, Default: false)
Output information as operations are performed. (For debugging purposes.)
Returns:
(List)
Requires:
Sample Use:
listFill("item1,item2,,,item3","-");
Returns: item1,item2,-,-,item3
Copy to Clipboard
function ListFill(list){
var tempList = "";
var lastIndex = 1;
var idx = 1;
if (ArrayLen(arguments) gt 1)fillChar = arguments[2];
else fillChar = " ";
if (ArrayLen(arguments) gt 2)delimiter = arguments[3];
else delimiter = ",";
if (ArrayLen(arguments) gt 3)verbose = arguments[4];
else verbose = false;
for (idx = 1; idx lte Len(list); idx = idx+1){
foundChar = mid(list,idx,1);
if (verbose)writeOutput("#asc(foundChar)#; ");
if (foundChar eq delimiter or idx eq Len(list)){
if (idx eq 1)tempList = ListAppend(tempList,fillChar,delimiter);
else{
if (mid(list,(idx-1),1) eq delimiter)tempList = ListAppend(tempList,fillChar,delimiter);
else{
if (idx neq Len(list))tempList = ListAppend(tempList,mid(list,lastIndex,(idx-lastIndex)),delimiter);
else tempList = ListAppend(tempList,mid(list,lastIndex,idx),delimiter);
};
};
lastIndex = idx;
};
};
if (verbose)writeOutput("
");
if (Right(list,1) eq delimiter)tempList = ListAppend(tempList,fillChar,delimiter);
return tempList;
};
// http://www.programmers.org/index.php/coldfusion-udf-library/?ckey=39&function=listFill



