CFLib.org – Common Function Library Project

listTrim(ThisList[, ThisDelimiter])

Last updated May 8, 2006

author

Christopher Jordan

Version: 1 | Requires: CF5 | Library: StrLib

Description:
ListTrim accepts a list and an optional delimiter value (defaults to comma if not passed), and then returns the same list of trimmed values.

Return Values:
Returns a string.

Example:

<cfset origList = "ray, jacob, lynn, noah, luke, anakin, walt, 4, 8, 15, 16, 23, 42">
<cfoutput>#listTrim(origList)#</cfoutput>

Parameters:

Name Description Required
ThisList List to trim. Yes
ThisDelimiter List delimiter. Defaults to a comma. No

Full UDF Source:

/**
 * Returns the list which was passed in after having trimmed each list item.
 * 
 * @param ThisList 	 List to trim. (Required)
 * @param ThisDelimiter 	 List delimiter. Defaults to a comma. (Optional)
 * @return Returns a string. 
 * @author Christopher Jordan (cjordan@placs.net) 
 * @version 1, May 8, 2006 
 */
function listTrim(ThisList) {
	var i = 0;
	var ThisDelimiter = ",";
	var ThisListItem = "";
	var ThisTrimmedList = "";
		
	// check for passed delimiter
	if(ArrayLen(Arguments) EQ 2){
		ThisDelimiter = Arguments[2];
	}
	for(i = 1; i LTE ListLen(ThisList,ThisDelimiter); i = i + 1){
		ThisListItem	= Trim(ListGetAt(ThisList,i,ThisDelimiter));
		ThisTrimmedList = ListAppend(ThisTrimmedList,ThisListItem,ThisDelimiter);
	}
	return ThisTrimmedList;
}
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