ColdFusion UDF Library - listSwitch

December 16th, 2008
«« Back to ColdFusion Library

Category:
   LIST

Description:
   Swaps the position of items in a list

Parameters:
  1. list (List, required)
           The list you wish to work with

  2. pos1 (Numeric, required)
           The index of the first item

  3. pos2 (Numeric, required)
           The index of the second item

  4. delimeter (String, Default: ,)
           the list delimeter


Returns:
       

Requires:
       

Sample Use:
       

Copy to Clipboard
function listSwitch(list,pos1,pos2){
	var temp = "";
	var delimiter = ",";
	if (ArrayLen(arguments) gte 2)delimiter = arguments[2];
	temp = ListGetAt(list,pos1,delimiter);
	list = ListSetAt(list,pos1,ListGetAt(list,pos2,delimiter),delimiter);
	list = ListSetAt(list,pos2,temp,delimiter);
	return list;
};
// http://www.programmers.org/index.php/coldfusion-udf-library/?ckey=31&function=listSwitch
  1. Micah LaCombe
    | #1

    This could be used to implement various sorting algorithms on your lists. (assuming the native listSort() did not meet your needs)

  1. No trackbacks yet.