Here is what I do:

After cffile:

<cfset FORM.Delims = "#chr(13)#" & "#chr(10)#">
<cfset Form.FileSize = #Len(variables.FileContent)#>
<cfset Form.FileLines = #ListLen(Variables.FileContent, Form.Delims)#>
<cfset variables.FileContent = #Replace(variables.filecontent, ",,", ", 
,", "all")#>
<cfset variables.FileContent = #Replace(variables.filecontent, ",,", ", 
,", "all")#>
<cfset FileContentLines = #ListToArray(variables.filecontent, form.delims)#>
<cfset filecontentlength = #ArrayLen(variables.filecontentlines)#>
<cfset ColumnName1 = "0">
<cfset ColumnName2 = "0">
<cfset ColumnName3 = "0">
<cfset FieldNameList = #variables.filecontentlines[1]#>
<cfset fieldqnty = #ListLen(variables.fieldnamelist, ",")#>
<cfset fieldnamearray = #ListToArray(variables.fieldnamelist, ",")#>

<cfloop index="FieldCounter" from="1" to="#variables.fieldqnty#" step="1">
<!--- One of these cfif lines for each column header whiching to pull 
into the database --->
<cfif #variables.fieldnamearray[variables.fieldcounter]# contains 
"Column Name Header Desc">
<cfset ColumnName1 = #variables.FieldCounter#>
</cfif>
</cfloop>

<cfloop index="FileProcess" from="2" to="#variables.filecontentlength#" 
step="1">
<cfset FieldDataArray = 
#ListToArray(FileContentLines[variables.FileProcess], ",")#>
<cfset Column1Value = #FieldDataArray[variables.ColumnName1]#>
<cfset Column2Value = #FieldDataArray[variables.ColumnName2]#>
<cfset Column3Value = #FieldDataArray[variables.ColumnName3]#>
<cfquery to insert data into database>
</cfloop>

Pete Ruckelshaus wrote:

>I'm a bit stuck.  I'm using cffile to read in a CSV file that is
>comma-delimited, quoted-value; only those values with commas in them
>are quoted, i.e.:
>
>123,this is a string,456,789
>124,"comma, baby",456,789
>
>I need to parse through this file and grab specific values.  I'm using
>a loop to get each row of data by using chr(13)chr(10) as line
>delimeters, then using listGetAt() to get each of the values in that
>row.
>
>Problem, of course, is the second example, when I really need the
>"comma, baby" value but listGetAt(list,2) would return "comma as the
>value for the second item and baby" as the third item in the list.
>
>Is there a simple solution?
>
>Thanks
>
>Pete
>
>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:199790
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to