there are a coupld of ways to do this.  you have

<CFSET filearray = ArrayNew(1)>
<CFLOOP List="#file_content#" Index="rc" Delimiters="#Chr(10)#">
        <CFSET rc = ArrayAppend(filearray, rc)>
</CFLOOP>

already.  therefore, each element of filearray[] is a pipe delimited list
over which you can iterate with another list loop.

one of the problems with the acove code is that it will whack the value of
RC each time through.  maybe use a throwaway variable to hold the boolean
result of arrayappend.

therefore, you would have...

<CFSET filearray = ArrayNew(1)>
<CFLOOP List="#file_content#" Index="rc" Delimiters="#Chr(10)#">
        <CFSET resultValue = ArrayAppend(filearray, rc)>
</CFLOOP>

then, replacing the inner set with another loop to break up each row of the
file, the code becomes...

<CFSET filearray = ArrayNew(2)>
<CFSET loopindex = 1>
<CFLOOP List="#file_content#" Index="rc" Delimiters="#Chr(10)#">
        <CFLOOP List="#rc#" INDEX="innerRC" DELIMITERS="|">
                <CFSET resultValue = ArrayAppend(filearray[loopindex], innerrc)>
        </CFLOOP>
        <CFSET loopindex = loopindex + 1>
</CFLOOP>

if you notice, i added an outer loop count to track where we were in the
file (WRT rows).

this should give you a two dimensional array.  the length of the first array
index is equal to the number of rows in the file.

as a side note, because of the nature of list loops, any empty element in
the file will fail this piece of code.  CF treats multiple delimiters (in
the inner loop's case, | symbols) as one delimiter (for some reason).

chris olive, cio
cresco technologies
[EMAIL PROTECTED]
http://www.crescotech.com



-----Original Message-----
From: Mike Kear [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 21, 2001 8:06 PM
To: CF-Talk
Subject: RE: Making 2D array


Thanks.  I already knew cfset filearray = arraynew(2).  It's the rest I
don't know how to do - how to break the text along the rows up into cells at
the pipe character. (the sample text I sent in my original message wrapped -
it was originally 4 lines only)

I need to do this so I can take this large text file, and break it up into 6
smaller files, delete some rows, delete some columns, reformat others, turn
them into tables, and save them as includes for a template to use based on a
form input.

SO thanks for your help Alex, but it doesn't tell me what I need to know.  I
have a large text file, I need to turn it into an array or structure or some
other format so I can manipulate the contents.   I figured using an Array
was the way to do it.

Isnt it?


So I still don't know how to do it.  (sigh)

Cheers,
Mike Kear
Windsor, NSW, Australia
AFP WebWorks




cfset filearray = arraynew(2)

but what are you going to do with the sencond dimension. why not just load
the data into a db table which is probably the easiest. Or put it in a
structure.

On Wed, 22 Aug 2001, Mike Kear wrote:

> I get  a large ASCII text file every month, and I want to read it into a
2D
> array so I can manipulate it then write it out to a HTML file in a series
of
> tables.   But I'm stumped with the second dimension of the array.  I can
> read it into one dimensional table like this:
>
>
> <CFSET filearray = ArrayNew(1)>
>   <CFLOOP List="#file_content#" Index="rc" Delimiters="#Chr(10)#">
>     <CFSET rc = ArrayAppend(filearray, rc)>
>   </CFLOOP>
>
> How do I make it into the two dimensional array instead?   Here's a sample
> of the text I get.  I want the elements in the second dimension to break
on
> the pipe character.
>
>
>
> [sample text]
> UBS Asset Management (Australia) Ltd|SBC0813AU|UBS Australian
Bond|339.30|7.77|5.31|8.02|0.42|~~~~~|8/55||
> Colonial First State Invest Aust Ltd|FSF0027AU|Col First State Wsale
AustBond|24.42|7.50|5.16|7.88|0.46|~~~~|7/55||
> IOOF Funds Management|IOF0012AU|IOOF Flex Tr
FI|6.23|6.91|5.14|7.47|1.12|~~~~~|5/55||
> Commonwealth Financial Services|COM0011AU|C'Wealth Bond
Fund|146.70|6.68|4.91|6.46|1.11|Not Rated|0/55||
> [end sample]
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to