You can also use the pipe as the delimiter. This code uses that and steps
over every other list element to get the group code and does the same to get
the description. The cfif just makes sure you don't have a stray | at the
end of the list.
<cfset groupText = "999|No Group Assigned |
AC |Activity |
BF |Brain Food |
BT |Books On Tape |
">
<cfset lstGroupLen = ListLen(groupText,"|")>
<cfloop from="1" to="#lstGroupLen#" step="2" index="idx">
<cfset grpDescIdx= idx + 1>
<cfif grpDescIdx LTE lstGroupLen>
<cfoutput>
Group Code is : #ListGetAt(groupText,idx,"|")#
Group Desc = #ListGetAt(groupText,grpDescIdx,"|")#<br>
<! --- You can do your insert(s) here --- >
</cfoutput>
</cfif>
</cfloop>
HTH,
Tim P.
----- Original Message -----
From: "Seamus Campbell" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Tuesday, June 05, 2001 7:41 AM
Subject: list and looping problems
> Hi - I have a text file in the below format:
>
> 999|No Group Assigned |
> AC |Activity |
> BF |Brain Food |
> BT |Books On Tape |
> etc |
>
>
> I want to insert/update this into a database table with field names
> GroupCode and GroupDesc
>
> so that for example
> 999 is inserted/updated into GroupCode
> and No Group Assigned is inserted/updated into GroupDesc etc etc
>
> So (I presume) I want the text file in this format so that it can be
> inserted/updated
> 999, No Group Assigned
> AC, Activity
> BF, Brain Food
> BT, Books On Tape
> etc
>
> I can't work out to get the text file into the second format
> I have got this far:
>
> <!--- CF reads the file --->
> <CFFILE action="READ" file="d:\InetPub\wwwroot\abc\Database\copy of
> group.txt" variable="group">
>
>
> <cfset CRLF="#CHR(13)##CHR(10)#">
> <!--- Loop thru each line --->
> <CFLOOP index="line" list="#group#" delimiters="#CRLF#">
> <!--- Loop thru each word --->
> <CFLOOP index="word" list="#line#" delimiters="#CHR(124)#">
> <cfoutput>
> #word#<BR>
> </cfoutput>
> </CFLOOP>
> </CFLOOP>
>
> But this does not give me what I need
>
> Can anybody help please (I am rather lost here)
> MTIA
> Seamus
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists