Skip to main content
Inspiring
June 25, 2008
Answered

Removing carriage returns

  • June 25, 2008
  • 2 replies
  • 552 views
I am trying to import an 8 column .csv file into my database unfortunately column 7 has a carriage return at the end which causes CF to throw the error, "Incorrect number of columns".

How do I get rid of the carriage returns during import?
This topic has been closed for replies.
Correct answer dempster
I assume that by using the "name" parameter you're trying to process the file as a query. That is why you're getting the error. You might be better off trying to process it as a block of text.

Get rid of the name and the contents of the file will be in the variable CFHTTP.FileContent . You'll have to develop a function to loop through the file and parse the contents. If every record has a CR in column 7, for example, you could extract each record by looking for each second CR. Then you treat it as a comma-delimted list.

2 replies

BKBK
Community Expert
Community Expert
June 26, 2008
My first attempt to filter out the carriage return would be something like

<cfset prematureEndOfRow = chr(13)&",">
<cfset content = replace(content, prematureEndOfRow, "," ,"all")>

dempsterCorrect answer
Inspiring
June 25, 2008
I assume that by using the "name" parameter you're trying to process the file as a query. That is why you're getting the error. You might be better off trying to process it as a block of text.

Get rid of the name and the contents of the file will be in the variable CFHTTP.FileContent . You'll have to develop a function to loop through the file and parse the contents. If every record has a CR in column 7, for example, you could extract each record by looking for each second CR. Then you treat it as a comma-delimted list.
spacehogAuthor
Inspiring
June 26, 2008
Dempster, thanks. It struck me as I read your answer. It is an extra step, but I am importing the file as text, removing the carriage returns, and then pushing it back into a query object using QueryNew()