CFLib.org – Common Function Library Project

ListJuxt(List1, List2[, Delim1][, Delim2][, Delim3])

Last updated September 20, 2004

author

Joshua Miller

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Juxtaposes two lists together making the first value of list1 the first value of the new list and the first value of list2 the second value of the new list, ad nauseum. Inserts blank values if one list is longer than the other.

Return Values:
Returns a string (delimited list of values).

Example:

<CFSET List1="1;2;3;4;5;6;7">
<CFSET List2="a,b,c,d,e,f,g">
<CFSET List3="1,2,3,4,5,6,7">
<CFSET List4="a,b">

<CFOUTPUT>
#ListJuxt(List1, List2, ";", ",")#<BR>
#ListJuxt(List1, List2, ";", ",", "|")#<BR>
#ListJuxt(List2, List3)#<BR>
#ListJuxt(List3, List4)#
</CFOUTPUT>

Parameters:

Name Description Required
List1 First list of delimited values. Yes
List2 Second list of delimited values. Yes
Delim1 Delimiter used for List1. Default is the comma. No
Delim2 Delimiter used for List2. Default is the comma. No
Delim3 Delimiter to use for the list returned by the function. Default is the comma. No

Full UDF Source:

/**
 * Juxtaposes two lists together in an &quot;every other value&quot; method.
 * Minor modifications by Rob Brooks-Bilson (rbils@amkor.com)
 * 
 * @param List1 	 First list of delimited values. (Required)
 * @param List2 	 Second list of delimited values. (Required)
 * @param Delim1 	 Delimiter used for List1.  Default is the comma. (Optional)
 * @param Delim2 	 Delimiter used for List2.  Default is the comma. (Optional)
 * @param Delim3 	 Delimiter to use for the list returned by the function.  Default is the comma. (Optional)
 * @return Returns a string (delimited list of values). 
 * @author Joshua Miller (josh@joshuasmiller.com) 
 * @version 1, September 20, 2004 
 */
function ListJuxt(list1,list2)
{
  var i=1;
  var newList="";
  var delim1=",";
  var delim2 = ",";
  var delim3 = ",";
  switch(ArrayLen(arguments)) {
    case 3:
      {
        delim1 = Arguments[3];
        break;
      }
    case 4:
      {
        delim1 = Arguments[3];
        delim2 = Arguments[4];
        break;
      }
    case 5:
      {
        delim1 = Arguments[3];
        delim2 = Arguments[4];          
        delim3 = Arguments[5];
        break;
      }        
  }

  for(i=1;i lte Max(ListLen(list1, delim1),ListLen(list2, delim2));i=i+1){
    if(i lte ListLen(list1, delim1)){
      newList=ListAppend(newList,ListGetAt(list1,i,delim1),delim3);
    }
    else{
      newList=ListAppend(newList,"",delim3);
    }
    if(i lte ListLen(list2, delim2)){
      newList=ListAppend(newList,ListGetAt(list2,i,delim2),delim3);
    }
    else{
      newList=ListAppend(newList,"",delim3);
    }
  }
  return newList;
}
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