CFLib.org – Common Function Library Project

ListElementPrepend(list, string[, delim])

Last updated September 21, 2004

author

SHUM Ting-hin

Version: 2 | Requires: CF5 | Library: StrLib

Description:
Prepends a string to every item in a list.

Return Values:
Returns a list.

Example:

<cfset list = "a,b,c">
<cfoutput>#listElementPrepend(list,"foo")#</cfoutput>

Parameters:

Name Description Required
list List to modify. Yes
string String to prepend. Yes
delim Delimiter. Defaults to a comma. No

Full UDF Source:

/**
 * Prepends a string to every item in a list.
 * Version 2 by Raymond Camden
 * 
 * @param list 	 List to modify. (Required)
 * @param string 	 String to prepend. (Required)
 * @param delim 	 Delimiter. Defaults to a comma. (Optional)
 * @return Returns a list. 
 * @author SHUM Ting-hin (gene_shum@iclp.com.hk) 
 * @version 2, September 21, 2004 
 */
function listElementPrepend(list,string) {
	var delim = ",";
	var i = "";
	
	if(arrayLen(arguments) gte 3) delim = arguments[3];
	
	for(i=1; i lte listLen(list); i=i+1) {
		list = listSetAt(list, i, string & listGetAt(list,i));
	}
	
	return list;
}
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