2

I'm just wondering if there is a way, in ColdFusion, to loop over an array of text and then loop over the text line by line ?

<cfloop file= "#ExpandPath('/file-path-here')#" index="theLine">
</cfloop>

The cfloop above loops through a file. However, I'm hoping to loop over an existing array that contains a lot of text. Then loop over each line of content. Is this possible with CF ?

Leigh
  • 28,765
  • 10
  • 55
  • 103
user125264
  • 1,809
  • 2
  • 27
  • 54
  • 1
    Arrays don't exist in real life. You create them with your programming language. So, if you are going to create an array that you then loop through, maybe you can achieve your goal without bothering with the array. Looking at your code for example, if you are looking at looping through the lines of a text file, you are better off treating the file as a chr(10) delimited list and looping through that. – Dan Bracuk Feb 07 '14 at 03:23
  • If you can provide a better description of what you're trying to accomplish by looping over the array and then looping over each line, you might get a better answer. – Russ Feb 08 '14 at 02:08

1 Answers1

3

Yes. Just loop over the array... Inside that loop you use the above loop for each file.

Sorry just re read the question. Yes you loop over the array. And then you treat the array items content as a list... Cfloop list= array item... Delimiter = Cr or lf

<cfloop array="#myarray#" index="arrayItem">
    <cfloop index="theLine" list="#arrayItem#" delimiters="#chr(10)##chr(13)#">
        <cfset doSomethingWithIt = theLine> 
    </cfloop>
</cfloop>
Gavin Pickin
  • 742
  • 3
  • 7