Skip to main content
Inspiring
July 13, 2009
Answered

Removing the Comma delimiter with something else in a File download

  • July 13, 2009
  • 3 replies
  • 871 views

I have a file whcih gets downloaded and then read and inserted into the database. The problem is when I read the belwo records below which should be 3 indexes, it breaks the index with the comma delimted  file into 5 indexes.

"","","Wonderful Expanded Cape, With 4/5 Bedrooms 2 Full Bths. Eik, Lr,Great Place, New"

How can I replace the comma delimited in the file when downloaded and the use that delimiter in my ListToArray .

<cfloop index="ind" list="#readlistings#" delimiters="#chr(13)##chr(10)#">
    <cfset i=ListToArray(ind, ",", true) />
    <cfoutput>
            #i[4]#
            <br><br>
    </cfoutput>

</cfloop>

    This topic has been closed for replies.
    Correct answer

    To retrieve the data's embedded in quotes, u can use the function in the following url  by passing ur string conataining commas as argument.

    http://www.cflib.org/udf/CSVtoArray

    3 replies

    Inspiring
    July 13, 2009

    If the delimiter commas are surrounded by double quotes, you have several options.

    1.  After uploading the file, read it with cfhttp instead of cffile.  The text qualifier attribute will be helpful.

    2. Set some variable to "," and use it as your delimiter.

    3. Replace the "," with a single character, like a pipe.

    Note that for options 2 and 3, you'll have to do something about the leading and trailing quotes.   For all three options, you'll need a plan for dealing with empty fields.

    umuayoAuthor
    Inspiring
    July 13, 2009

    Dan,

    Do you have an example of this?

    Inspiring
    July 13, 2009

    Make sure that the directory containing your file allows http requests.  It's really annoying when it doesn't.

    <cfhttp url="your file"

    name = "YourQuery"

    columnnames = "f1,f2,f3"

    delimiter = ","

    textqualifier = """">

    <cfdump var = "#YourQuery#">

    Dileep_NR
    Inspiring
    July 13, 2009

    plz refer

    http://www.bennadel.com/blog/274-Java-Exploration-in-ColdFusion-java-io-LineNumberReader.htm

    Correct answer
    July 13, 2009

    To retrieve the data's embedded in quotes, u can use the function in the following url  by passing ur string conataining commas as argument.

    http://www.cflib.org/udf/CSVtoArray