Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Reading .csv Files & Empty List Elements

Participant ,
Aug 13, 2008 Aug 13, 2008
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.
918
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 13, 2008 Aug 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 13, 2008 Aug 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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 13, 2008 Aug 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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 13, 2008 Aug 13, 2008
LATEST
quote:

Originally posted by: Dan Bracuk
Step 2, - replace all consectutive delimiters with the delimiter followed by the word null, followed by the next delimiter.



You also need to handle cases where the first or last element is empty.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 13, 2008 Aug 13, 2008
Did you try running the replace twice?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 13, 2008 Aug 13, 2008
Put it in a while loop.

While your string contains ",,",
run the replace function
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources