Note that the very useful function GetToken() operates under the same
limitation.  In other words:

<cfset some_text = "1,2,,4,5">
<cfset third_item = GetToken( some_text, 3, ",")>
<cfoutput>#third_item#</cfoutput>

Will output "4" instead of null. When I've used CF to parse files, I usually
use an outer loop to isolate lines of text by looking for CHR(13), then
perform a Replace() on each line as I'm about to process it. Here is a
partial example from something I did recently.

        <cfparam name="FORM.delimiter" default = "">

        <!--- file name determination stuff snipped --->

        <cffile action="READ"
                file="#v_filename#"
                variable="v_data">

        <!--- Initialize loop --->
        <cfset v_record_start = 1>
        <cfset v_record_end = Find("#CHR(13)#",  v_data, v_record_start)>
        <cfloop condition="v_record_start lt Len(v_data)">
                
                <!--- Extract single line of file --->
                <cfset v_cur_rec = Mid( v_data, v_record_start,
v_record_end-v_record_start+1)>

                <!--- Consecutive delimiters are ignored by GetToken, so we
need to pad with a space so that they will be recognized --->
                <cfset v_cur_rec = Replace( v_cur_rec,
"#FORM.delimiter##FORM.delimiter#", "#FORM.delimiter# #FORM.delimiter#",
"ALL")>

                <!--- process record here --->
                <cfset v_prop_image_id = Trim(GetToken(v_cur_rec, 1,
FORM.delimiter))>
                <cfset v_entity_id = Trim(GetToken( v_cur_rec, 2,
FORM.delimiter))>

                <!--- ... and so on, more columns are extracted and
eventually a query is executed if the conditions are right ... --->
                
                <!--- finish loop --->
                <cfset v_record_start = v_record_end+1>
                <cfset v_record_end = Find( "#CHR(13)#", v_data,
v_record_start)>
                <cfif v_record_end eq 0>
                        <cfset v_record_end = Len(v_data)>
                </cfif>
        </cfloop>

As an aside, CFHTTP is generally a much faster way to parse a text file into
a structure. In case you don't know, you can give CFHTTP a query name, a
column list and a delimiter and it will parse the file specified by the url
into a query result. I can't recall off the top of my head whether this
functionality suffers the consecutive delimiter problem, but I can attest to
its speed over using CFFILE and parsing as I've outlined above. The only
problem is that often the file I want to access is not in a public doc root
and thus can't be accessed by CFHTTP, but I have jumped through hoops to be
able to use this feature in the past because it works so well.

I wish they would just change CFFILE so that you could go straight to a
query structure too!

-Chris Gilbert, Fodors.com

-----Original Message-----
From: kaigler [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 22, 2001 12:31 PM
To: CF-Server
Subject: cfloop - limitation


Here is the example from allaire regarding cfloop:

<cfloop index = "ListElement"
   list = "John/Paul,George::Ringo"
   delimiters = ",:/">
     <cfoutput>#ListElement#</cfoutput><BR>
</cfloop>
Delimiters can be specified in any order. Consecutive delimiters are 
treated as a single delimiter; thus the two colons in the previous example 
are treated as a single delimiter between "George" and "Ringo."


Is it just me or is the fact that consecutive delimiters are treated as a 
single delimiter a major flaw?

Does anyone have a work around for this other thanscanning the file from 
byte 1 to the last byte and manipulating the data so that is does not look 
like consecutive delimiters?

kaigler
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
------------------------------------------------------------------------------
To unsubscribe, send a message to [EMAIL PROTECTED] with 
'unsubscribe' in the body or visit the list page at www.houseoffusion.com

Reply via email to