title: ArrayToList() ColdFusion?
body: <p>I have a query that I'm looping through and appending to array. After loop is done I use <code>ArrayToList()</code> with tab delimiter. Problem is that between each row I have an extra empty column. My guess is that command converts last comma to tab delimiter. I still could not find the way to prevent that. Here is my code:</p>
  
  <pre><code>&lt;cfspreadsheet action="read" src="#urlPath#\Roster.xlsx" query="excelData" headerrow="1"&gt;
  
  &lt;cfset metadata = getMetaData(excelData)&gt;
  &lt;cfset colList = ""&gt;
  
  &lt;cfloop index="col" array="#metadata#"&gt;
      &lt;cfset colList = listAppend(colList, col.name)&gt;
  &lt;/cfloop&gt;
  
  &lt;cfset buffer=ArrayNew(1)&gt;
  &lt;cfset crlf=chr(13)&amp;chr(10)/&gt;
  
  &lt;cfoutput query="excelData"&gt;
      &lt;cfloop index="i" list="#colList#"&gt;
          &lt;cfset ArrayAppend(buffer,excelData[i][currentRow])&gt;
      &lt;/cfloop&gt;
  
      //prevents blank row to be created on the end
      &lt;cfif excelData.currentrow eq excelData.recordcount&gt;
          &lt;cfset ArrayAppend(buffer,"")&gt;
      &lt;cfelse&gt;
          &lt;cfset ArrayAppend(buffer,crlf)&gt;
      &lt;/cfif&gt; 
  &lt;/cfoutput&gt;
  
  //setting tab delimiter 
  &lt;cfset test = arrayToList(buffer,chr(9))/&gt;
  
  &lt;cfscript&gt; 
      FileWrite("#urlPath#\Test_Text.txt", "#test#"); 
  &lt;/cfscript&gt;
  </code></pre>
  
  <p>Here is the output after I run this code:</p>
  
  <p><a href="https://i.stack.imgur.com/MTcCY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MTcCY.png" alt="enter image description here"></a></p>
  
  <p>And here is what I need my output to look like:</p>
  
  <p><a href="https://i.stack.imgur.com/T1HJG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T1HJG.png" alt="enter image description here"></a></p>
  
  <p>I choose <code>ArrayAppend()</code> because it's much faster than the <code>ListAppend()</code>, if anyone can help whit this problem please let me know. Thank you.</p>
  
  <p>If I do cfdump of buffer array this is the output:</p>
  
  <pre><code>array
  1   LAST_NAME
  2   FIRST_NAME
  3   BIRTH_DATE 
  4   
  5   Milos
  6   TestOne
  7   11/16/97
  8
  </code></pre>
  
  <p>Looks like between each row is the blank space row 4 and 8. This is how I fixed the date format issue:</p>
  
  <pre><code>&lt;cfoutput query="excelData"&gt;
          &lt;cfset thisRow = []&gt;
          &lt;cfset count = 1&gt;
          &lt;cfloop index="i" list="#colList#"&gt;
              &lt;cfif count EQ 3 AND excelData[i][currentRow] NEQ "BIRTH_DATE"&gt;
                  &lt;cfset ArrayAppend(thisRow,dateFormat(excelData[i][currentRow],"mm/dd/yyyy"))&gt;
              &lt;cfelse&gt;
                  &lt;cfset ArrayAppend(thisRow,excelData[i][currentRow])&gt;
              &lt;/cfif&gt;
              &lt;cfset count++&gt;
          &lt;/cfloop&gt;
          &lt;cfset ArrayAppend(buffer,arrayToList(thisRow, chr(9)))&gt;
      &lt;/cfoutput&gt;
  </code></pre>