EasyCFM.COM ColdFusion Forums / ColdFusion Applications / getting rid of space in file

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: getting rid of space in file

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

anujgarg
10-18-2006 @ 10:46 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 11
Joined: Sep 2006

Hi

I am worried to solve out the following problem:

I am uploading a file having pipe (|) separated list as follows:



New Cal - Import |New Cal - Import desc|2006-10-13 00:00:00.0|2006-10-13
23:59:59.0|2006-10-18 00:00:00.0|Y|Y|Y

multiple|tasks|2006-10-12 07:00:00.0|2006-10-12
23:59:59.0|2006-10-16 16:30:46.531906|Y|N|Y

test|test desc<br />|2006-10-11
07:00:00.0|2006-10-11 23:59:59.0|2006-10-09 00:00:00.0|Y|N|Y

test cal Calendar Created||2006-08-01 22:19:25.983302|2006-08-01 22:19:25.983302|2006-08-01
22:19:25.983302|Y|N|Y

But in the last of this file, I am having a gap which is responsible to loopthrough it two times in the following code:

<cffile action="upload" destination="#UploadPath#" filefield="filename" nameconflict="makeunique">
   <cffile action="read" file="#UploadPath#/#cffile.ServerFile#" variable="fileData">
   <cfloop index="record" list="#replace(fileData,"||","| |","ALL")#" delimiters="#chr(10)##chr(13)#">
      <cfset tmp1 = #replace(listgetat(record,1,"|"),"'","\'")#>
       <cfset tmp2 = #replace(listgetat(record,2,"|"),"'","\'")#>

Here, the last line is creating the problem and flashing the error:


In function ListGetAt(list, index [, delimiters]), the value of index, 2, is not a valid as the first argument (this list has 1 elements). Valid indexes are in the range 1 through the number of elements in the list.

Kindly suggest what to do?

TIA

Anuj

Webmaster
10-18-2006 @ 1:10 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4542
Joined: Jan 2002

here is what I would do:

<!--- upload the file --->
<cffile action="upload"
        destination="#UploadPath#"
        filefield="filename"
        nameconflict="makeunique">
<!--- read the file --->
<cffile action="read"
        file="#UploadPath#/#cffile.ServerFile#"
        variable="fileData">
          
<!--- Add a space to the data before looping through it --->
<cfset tFileRead = ReplacenoCase(fileData, "|", "| ", "ALL") />

<!--- Now loop through the data --->
<cfloop index="record" list="#tFileRead#" delimiters="#chr(10)##chr(13)#">

       <!--- reference each element - and TRIM() out the added space we inserted above --->
      <cfset tmp1 = trim(listgetat(record, 1, "|")) />
      <cfset tmp2 = trim(listgetat(record, 2, "|")) />
       
</cfloop>

Let me know if you have any further questions or comments.

Pablo Varando
Senior Application Architect
EasyCFM.COM, LLC.

904.483.1457 \\ mobile
webmaster@easycfm.com \\email

anujgarg
10-19-2006 @ 7:47 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 11
Joined: Sep 2006

Thanks! 'trim' worked. Smile


Website Designed and Developed by Pablo Varando.