ColdFusion UDF Library - listNatural
December 16th, 2008
«« Back to ColdFusion Library
Category:
LIST
Description:
Converts a List into a Human Readable List
Parameters:
Returns:
(String) Human Readable List ex. "one, two, and three"
Requires:
Sample Use:
#listNatural("one,two,three")#
Copy to Clipboard
Category:
LIST
Description:
Converts a List into a Human Readable List
Parameters:
- list (List, required)
The list you wish to make natural. - delimeter (String, Default: ,)
The delimiter used in list. - comma (String, Default: ,)
The string to seperate each list item with. - amp (String, Default: &)
The string to use on the last list item.
Returns:
(String) Human Readable List ex. "one, two, and three"
Requires:
Sample Use:
#listNatural("one,two,three")#
Copy to Clipboard
function listNatural(list){
var delimiter = ",";
var comma = ",";
var amp = "&";
var string = "";
var loop = 0;
if (ArrayLen(arguments) gte 2)delimiter = arguments[2];
if (ArrayLen(arguments) gte 3)comma = arguments[3];
if (ArrayLen(arguments) gte 4)amp = arguments[4];
if (ListLen(list,delimiter)){
if (ListLen(list,delimiter) gt 1){
for (loop = 1; loop lte ListLen(list,delimiter); loop = IncrementValue(loop)){
if (loop eq ListLen(list,delimiter))string = string & " " & amp & " " & ListGetAt(list,loop,delimiter);
else{
if (loop lt ListLen(list,delimiter)-1)string = string & ListGetAt(list,loop,delimiter) & comma & " ";
else string = string & ListGetAt(list,loop,delimiter) & " ";
};
};
}
else string = list;
};
return string;
};
// http://www.programmers.org/index.php/coldfusion-udf-library/?ckey=36&function=listNatural



