Seamus,


This is a job for regular expressions. First of all, include this function
in your page (it returns a structure containing all matches):


<!--- Like REFind(), but returns *all* matches --->
<CFFUNCTION NAME="REFindAll" OUTPUT="false" RETURNTYPE="struct">
   <CFARGUMENT NAME="regex" TYPE="string" REQUIRED="yes">
   <CFARGUMENT NAME="text" TYPE="string" REQUIRED="yes">


   <!--- Define local variables --->
   <CFSET var results=StructNew()>
   <CFSET var pos=1>
   <CFSET var subex="">
   <CFSET var done=FALSE>


   <!--- Initialize results structure --->
   <CFSET results.len=ArrayNew(1)>
   <CFSET results.pos=ArrayNew(1)>


   <!--- Loop through text --->
   <CFLOOP CONDITION="NOT done">


      <!--- Perform search --->
      <CFSET subex=REFind(ARGUMENTS.regex, ARGUMENTS.text, pos, TRUE)>


      <!--- Anything matched? --->
      <CFIF subex.pos[1] IS 0>
         <!--- Nothing found, outta here --->
         <CFSET done=TRUE>
      <CFELSE>
         <!--- Got one, add to arrays --->
         <CFSET ArrayAppend(results.len, subex.len[1])>
         <CFSET ArrayAppend(results.pos, subex.pos[1])>
         <!--- Reposition start point --->
         <CFSET pos=subex.pos[1]+subex.len[1]>
      </CFIF>


   </CFLOOP>


   <!--- If no matches, add 0 to both arrays --->
   <CFIF ArrayLen(results.len) IS 0>
      <CFSET ArrayAppend(results.len, 0)>
      <CFSET ArrayAppend(results.pos, 0)>
   </CFIF>


   <!--- And return results --->
   <CFRETURN results>
</CFFUNCTION>


Here is the processing itself:


<!--- Get all records --->
<CFSET records=REFindAll("(BOOS\|).*?(BOOE\|)", myData)>


<!--- Loop through them --->
<CFLOOP INDEX="i" FROM="1" TO="#ArrayLen(records.pos)#">
<!--- Your per record processing goes here --->
<CFSET record=Mid(myData, records.pos[i], records.len[i])>
<CFOUTPUT>#record#</CFOUTPUT>
<HR>
</CFLOOP>


The REFindAll() call gets the matches, and the <CFLOOP> loops through them.
Then just replace the processing in the loop with your own processing.


Hope this helps.


--- Ben



  _____  

From: Seamus Campbell [mailto:[EMAIL PROTECTED]
Sent: Sunday, May 30, 2004 11:47 AM
To: CF-Talk
Subject: parsing help for a slow learner

Hi

I'm hoping some-one can help me.
I have to parse a file to insert data into a database, and I'm  
stuck on the initial parsing. (I have some sort of mental block  
when it comes to this sort of stuff)

A sample of the file is at the bottom of this email.

each record is starts with BOOS| and ends with BOOE|

At the moment I am reading the file, then replacing the BOOS|  
with a ~ and looping thru the file using the new delimiter (~)
This way I can get each record but I can't seem to then get each  
field.

I have tried:

<CFFILE file="#myFile#" action="" variable="myData">
<cfset myDelim = "BOOS|">
<cfset myData = Replace(myData,myDelim,"~","ALL")>

<cfloop index="myLine" list="#myData#" delimiters="~">

<cfloop index="myRecord" list="#myLine#"  
delimiters="#Chr(10)##Chr(13)#">

<cfset Field = left(Trim(myLine),4)>
<cfset Data = "" "|"))>
<!--- Input data here --->

</cfloop>
<hr>

</cfloop>

But this seems to get BOOK and then the rest of the record ie  
doesn't see a new line

Any help at all would be greatly appreciated

Seamus

++++++++++++++++++++++++++++++++++++++++
BOOS|
BOOK|000004
TRAN|D
ANAM|ROTH, WALTER E.
TNAM|NORTH QUEENSLAND ETHNOGRAPHY Bulletin No.4 : GAMES, SPORTS AND  
AMUSEMENTS
PBLS|Home Secretary's Department Brisbane, 1902
SUB1|ABORIGINAL CULTURE, AUSTRALIA HISTORY, NATIVE MONOGRAPHS, 19TH  
CENTURY SPORTS
DESC|Good. 1st. 13.25 x 8.25. a Monograph of 39pp, illustrated by  
photograph and drawings, the endpapers have browned and the  
exceedingly plain covers have surface tarnish but a bright  
interior on superior paper. Walter E.Roth was Queensland's  
"Northern Protector of Aboriginals" previously he was "Demy of  
Magdalen College, Oxford".
PRIC|35
UPDT|10/05/2004
UPTM|12:44:38 PM
BCAT|Sold
ABLE|1
UBID|1
STAT|Sold
PPRC|0
PDSC|QLD
BOOE|
BOOS|
BOOK|000015
TRAN|A
ANAM|Paul De Nooijer
TNAM|Magie in De Vleeshal : De Fotografie Van Paul De Nooijer
PBLS|Middleburg: Deze Publikatie, 1987
SUB1|PAUL DE NOOJIER, NETHERLANDS PHOTOGRAPHER, DUTCH PHOTOGRAPHY ,  
DRAMATIC VISUAL ART
DESC|Illustrated Card. Very Good. 1st. Softcover. 8.5 x 9.25. 50pp  
with triple expanding heart "111 Kleurprints". A major art work by  
an icon Dutch photgrapher, covers a little rubbed. "In all my work  
I have wanted to involve the framework in the representation so as  
to suggest what is taking place behind it."
PRIC|25
UPDT|8/05/2004
UPTM|1:36:35 PM
BCAT|Art
ABLE|1
UBID|3
STAT|For Sale
PPRC|0
PDSC|art
BOOE|
BOOS|
BOOK|000018
TRAN|A
ANAM|A H Archibald Henry Rea, Illustrated by Max Cowper
TNAM|LINDORES ABBEY and It's Historic Associations
PBLS|Dundee: James P. Mathew, 1902
SUB1|LINDORES ABBEY, ECCLESIASTICAL ARCHITECTURE, SCOTTISH PILES  
MAX COWPER
DESC|Illustrated Boards. Good. 1st. Travel and Historic Guide. 7.25  
x 5. 153pp, a.e.g. rubs to the bottom extremities bumps to the  
spine edges. 15 illus. and a ground plan. "Of all the valleys in  
Scotland, perhaps not one surpasses the valley of the Tay for  
beauty of scenery, grandeur of surroundings, and wealth of places  
famous in the annals of our country."
PRIC|20
UPDT|8/05/2004
UPTM|1:46:32 PM
BCAT|England / Ireland / Scotland / Wales
ABLE|1
UBID|4
STAT|For Sale
PPRC|0
PDSC|ENG
BOOE|
BOOS|
BOOK|000022
TRAN|A
ANAM|NORMAN BUCHANAN
TNAM|Learn to Draw
PBLS|London: Frederick Warne, 1964
SUB1|ART EDUCATION, BECOMING AN ARTIST, LEARNING TO DRAW,
DESC|Illustrated Boards. Very Good/Fair. 1st. 11.25 x 8.5. 66pp,  
d/w : worn, amateur repairs. clipped. Book : slight darkening of  
the paper. sections include Ways and Means, Teaching Yourself -  
Practical, Further Practice Out of Doors, Figure Drawing. "One of  
the ideas running through this book is that if a student can make  
a really good drawing of a potato.."
PRIC|22.5
UPDT|8/05/2004
UPTM|11:50:22 AM
BCAT|Art
ABLE|1
UBID|5
STAT|For Sale
PPRC|0
PDSC|art
BOOE|
++++++++++++++++++++++++++++++++++++++++

Seamus Campbell   Boldacious WebDesign
http://www.boldacious.com   ~~~~   [EMAIL PROTECTED]
ph 02 6297 4883  mob 0410 609 267
  _____
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to