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

Reading from CSV

Participant ,
Mar 16, 2010 Mar 16, 2010

Copy link to clipboard

Copied

Hi all, I am reading from a text file but some of the columns of csv may not have data. Is there a way to skip those?

I am getting an error ...

n function ListGetAt(list, index [, delimiters]), the value of index, 43, is not a valid as the first argument (this list has 42 elements). Valid indexes are in the range 1 through the number of elements in the list.

------------------------------------

    <cffile action="read" file="#CurrDir#ResourceList.csv" variable="csvfile">
    <cfset Validate = createobject("component", "rms_t.ValidateResource")>
     <cfset msg = "">
         <cfset counter = 1>
    
     <cfloop index="index" list="#ListRest(csvfile)#" delimiters="#chr(10)##chr(13)#">

          <cfif listgetAt('#index#',43) neq "" and listgetAt('#index#',43) eq 'Y'>         </cfif>

TOPICS
Advanced techniques

Views

902

Translate

Translate

Report

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

correct answers 1 Correct answer

Valorous Hero , Mar 16, 2010 Mar 16, 2010

Actually the problem is that ColdFusion list functions have long had the feature of ignoring empty elements.  I.E. ColdFusion sees the list A,B,,C,,D,E as five items long not seven.  There is a valid, if somewhat esoteric, reason for this behavior but it is a real pain the tush when you do not want it to do this.

As of ColdFusion 9, there is not a parameter in the list functions to tell ColdFusion to count the empty list elements.  But if you are working with CF8 or earlier, you will have to hand

...

Votes

Translate

Translate
Valorous Hero ,
Mar 16, 2010 Mar 16, 2010

Copy link to clipboard

Copied

Actually the problem is that ColdFusion list functions have long had the feature of ignoring empty elements.  I.E. ColdFusion sees the list A,B,,C,,D,E as five items long not seven.  There is a valid, if somewhat esoteric, reason for this behavior but it is a real pain the tush when you do not want it to do this.

As of ColdFusion 9, there is not a parameter in the list functions to tell ColdFusion to count the empty list elements.  But if you are working with CF8 or earlier, you will have to handle the situation yourself.  There are functions to do this for you on the cflib.org web site.  But if you care to role your own, the common technique is to run a replace on the list putting some type of data between the empty list delimiters that you know represents an empty element, but CF sees as a list value.  Commonly empty single quote '' or pipe ||.

Votes

Translate

Translate

Report

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 ,
Mar 16, 2010 Mar 16, 2010

Copy link to clipboard

Copied

Thank u Ian

Votes

Translate

Translate

Report

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 ,
Mar 17, 2010 Mar 17, 2010

Copy link to clipboard

Copied

ianskinner wrote:

Actually, the problem is that ColdFusion list functions have long had the feature of ignoring empty elements.  I.E. ColdFusion sees the list A,B,,C,,D,E as five items long not seven.  There is a valid, if somewhat esoteric, reason for this behavior; but it is a real pain in the tush when you do not want it to do this.

As of ColdFusion 9, there is not now a parameter in the list functions to tell ColdFusion to count the empty list elements.  But if you are working with CF8 or earlier, you will have to handle the situation yourself.  There are functions to do this for you on the cflib.org web site.  But if you care to role roll your own, the common technique is to run a replace on the list putting some type of data between the empty list delimiters that you know represents an empty element, but CF sees as a list value.  Commonly empty single quotes '' or pipes ||.

I am glad I was able to help, but I just had to correct some of my typos for posterity.

Votes

Translate

Translate

Report

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
Enthusiast ,
Mar 25, 2010 Mar 25, 2010

Copy link to clipboard

Copied

LATEST

>As of ColdFusion 9, there is not a parameter in the list functions to  tell ColdFusion

There is NOT? Well, the docs prove you right. There isn't.

Actually, I know you meant "now", not "not". There is. And for ListLen(), this is an undocumented feature. It's a bug in the CFML reference.

(Edit: Damn, I didn't notice the reply, where the obvious typo was discussed. Old jokes are old. But there's still a bug in the docs)

-Fernis

Votes

Translate

Translate

Report

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
Documentation