Skip to main content
Inspiring
August 13, 2008
Question

Reading .csv Files & Empty List Elements

  • August 13, 2008
  • 4 replies
  • 1022 views
I have an application allowing users to upload .csv files for import into a database.

The issue is however, that in some cases every column in the csv file will be populated, and in others, not.

As ColdFusion ignores empty list elements I cannot accurately import data based on it's column numbers.

I'm curious how others get around this issue.
    This topic has been closed for replies.

    4 replies

    Inspiring
    August 14, 2008
    Put it in a while loop.

    While your string contains ",,",
    run the replace function
    Inspiring
    August 14, 2008
    Did you try running the replace twice?
    Inspiring
    August 13, 2008
    I just did something like this. My solution was:

    Step 1 - Outer loop, read each line of the file.

    Step 2, - replace all consectutive delimiters with the delimiter followed by the word null, followed by the next delimiter.

    Step 3 - inner loop. loop through that modified row and process it accordingly.
    Inspiring
    August 13, 2008
    quote:

    Originally posted by: Dan Bracuk
    I just did something like this. My solution was:

    Step 1 - Outer loop, read each line of the file.

    Step 2, - replace all consectutive delimiters with the delimiter followed by the word null, followed by the next delimiter.

    Step 3 - inner loop. loop through that modified row and process it accordingly.


    Tried that earlier, but didn't have much luck...

    The attached code just ends up producing this result:

    first_name,0,last_name,0,,0,,0,,0...

    Inspiring
    August 13, 2008
    ckbentdesigns wrote:
    > As ColdFusion ignores empty list elements

    Yes, most list functions ignore empty elements. If you are using CF8, try the listToArray function. It has a new attribute includeEmptyElements.

    Otherwise, there are several solutions. I listed a few of them in this thread. Though there are others. You should google something like: ColdFusion csv Files Empty List Elements to see other options and the +/- of each.
    http://www.tek-tips.com/viewthread.cfm?qid=1490791&page=1