I have a CSV file that I need to build a web interface for uploading
into our Oracle database.  One of the things I noticed is this data
has a CR within it, such as blah,1,12042004,"this has a CR right
here[]and then more text",blahblah,45 ... and each line ends with a
CR.  I was wanting to use some of the methods(java.io.StringReader and
java.io.BufferedReader) that I have seen posted on the list recently,
just to learn another way but these CRs are throwing things off.  Best
I can tell the readLine() function that is part of the BufferedReader
gets to that CR that is with double quotes and sees it as a new line. 
Would there be some way to make it overlook this?

Here is some example code, this was taken directly from a function
recently posted to the list:

<cfscript>
 var linesArray = ArrayNew(1);
 var jReader = 
createObject("java","java.io.StringReader").init(arguments.inString);
 var jBuffer = createObject("java","java.io.BufferedReader").init(jReader);
 var line = jBuffer.readLine(); 
</cfscript>

<cftry>
 <!--- 
Unlike Java, CFML has no notion of null, but this is quite a special
case.   Whenever readLine() reach the end of the file, it return a
Java null,  as soon as   the  BufferedReader return null, ColdFusion
"erase" the line variable,  making it undefined.        Here we leverage
this somewhat weird behavior by using it as test condition for the
loop
 --->
<cfloop condition="#IsDefined("line")#">
 <cfset ArrayAppend(linesArray, line)>
 <cfset line=jBuffer.readLine()>
</cfloop>

<cfset jBuffer.close()>
<cfcatch type="any">
<!--- 
Something went wrong; we better close the stream anyway, just to be
safe and leave no garbage behind
--->
 <cfset jBuffer.close()>
 <cfthrow message="tmt_csv: Failed to read lines from string" type="tmt_csv">
</cfcatch>
</cftry>
<cfreturn linesArray>

-- 
Aaron Rouse
http://www.happyhacker.com/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Special thanks to the CF Community Suite Gold Sponsor - CFHosting.net
http://www.cfhosting.net

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:186450
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=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to