Reputation: 3792
I have a text file in the format:
ABC | 123
DEF | 456
I've tried all sorts of things but can't get out what I need. What I need to be able to do is loop through each row and pick out (in the above example) ABC
and 123
separately, as well as DEF
and 456
<cfloop file="#application.sLibPath#301.txt" index="FileLine">
<cfoutput>#listgetat(FileLine,1)#, #listgetat(FileLine,2)#</cfoutput><br>
</cfloop>
I've tried that but it doesn't work, i.e., it breaks. Anyone have any suggestions?
Upvotes: 0
Views: 367
Reputation: 13548
You are missing the delimiter portion of the ListGetAt
function. By default the delimiter is a ,
(comma) but in your case you want a |
character.
Try this:
<cfoutput>#listgetat(FileLine,1,"|")#, #listgetat(FileLine,2,"|")#</cfoutput><br>
Note: looking at your example data this might include some white space as well. Something like "ABC " and " 123" (notice the spaces). You can use the Trim()
function to remove those.
<cfoutput>#Trim(listgetat(FileLine,1,"|"))#, #Trim(listgetat(FileLine,2,"|"))#</cfoutput><br>
Documentation for the ListGetAt function
Upvotes: 7