Help with Comma Delimited File
Author |
Message |
dru.. #1 / 7
|
 Help with Comma Delimited File
Hey! Does anyone have some code fragments that can parse this: "Data1_1","Data1_2, ... "DataR_C" "Data2_1","Data2_2, ... etc. Where the data are in a flat file format in rows and columns. Any code fragments would be appreciated. Or tell me where I can go for some. < Please no jokes here. <g> Thank you Danny _+_+_+_+_+_+_+_+_+_+_+_+_+_+ Danny Rubis
LooK Incoporated
+_+_+_+_+_+_+_+_+_+_+_+_+_+_
|
Wed, 30 Jun 1999 03:00:00 GMT |
|
 |
rb.. #2 / 7
|
 Help with Comma Delimited File
Quote:
>Hey! >Does anyone have some code fragments that >can parse this: >"Data1_1","Data1_2, ... "DataR_C" >"Data2_1","Data2_2, ... >etc. >Where the data are in a flat file format >in rows and columns. >Any code fragments would be appreciated. >Or tell me where I can go for some. < Please no jokes here. <g> >Thank you Danny >_+_+_+_+_+_+_+_+_+_+_+_+_+_+ >Danny Rubis
>LooK Incoporated
>+_+_+_+_+_+_+_+_+_+_+_+_+_+_
This is can be done quite simply: indsn = 'filename.csv' do while(lines(indsn) > 0) line = linein(indsn); parse value line with '"' data_1 '","' data_2 '","' data_3 .... /* do your processing here * i.e. */ say data_1 data_2 data_3 end HTH, Reinhardt Reinhardt Behm, D-64569 Nauheim, Germany
|
Wed, 30 Jun 1999 03:00:00 GMT |
|
 |
Larry G. Nottingh #3 / 7
|
 Help with Comma Delimited File
:> :>Hey! :> :>Does anyone have some code fragments that :>can parse this: :> :>"Data1_1","Data1_2, ... "DataR_C" :>"Data2_1","Data2_2, ... :>etc. :> :>Where the data are in a flat file format :>in rows and columns. :> :>Any code fragments would be appreciated. :> :>Or tell me where I can go for some. < Please no jokes here. <g> :> :>Thank you Danny :> Danny, The following is some code from a VX-REXX app that I wrote that reads a text file created by exporting from a db. The code processes a complete line placing each string of text within " " into a seperat subscripted variable. It accounts for omitted strings (,,"...",," ",,). Hope this helps. do while(length(DataLine) > 0) select when substr(DataLine,1,1) = '"' then do parse var Dataline '"' PhoneVar.Index '"' DataLine parse var Dataline ',' DataLine end when substr(DataLine,1,1) = ',' then do parse var Dataline ',' DataLine PhoneVar.Index = 'N/A' end otherwise do parse var Dataline PhoneVar.Index ',' DataLine end end Index = Index + 1 end ------------------------ Larry G. Nottingham
------------------------
|
Wed, 30 Jun 1999 03:00:00 GMT |
|
 |
Andre Do #4 / 7
|
 Help with Comma Delimited File
DR> Does anyone have some code fragments that DR> can parse this: DR> "Data1_1","Data1_2, ... "DataR_C" DR> "Data2_1","Data2_2, ... DR> etc. Roughly, not tested : /**/ filename='x.txt' line=0 DO WHILE Lines(filename)>0 x=LineIn(filename) line=line+1 DO WHILE x<>'' PARSE VAR x '"' y '"' ',' x SAY 'Found on line' line ':' y END END CALL LineOut filename EXIT Ave, Andre Doff
|
Wed, 30 Jun 1999 03:00:00 GMT |
|
 |
Lou Pepp #5 / 7
|
 Help with Comma Delimited File
Danny, I copied this from an rexx program I have. It reads an ascii deliminated line into individual variables. First I change all blanks to underscores _ , parse the line and change the underscores back to blanks later on. i is the asscii deliminated line. x = changestr(' ',i,'_') delim = '","' delim = '","' parse var i +1 year (delim) . (delim) ., (delim) sortname (delim) . (delim) ln (delim) fn, (delim) busname (delim) addr (delim) addr1, (delim) addr2 (delim) city (delim) st_zip_plus, (delim) areac (delim) phone (delim) fax, (delim) . (delim) . (delim) . (delim) cat1, (delim) cat2 (delim) cat3 (delim) mailcd (delim) .
|
Thu, 01 Jul 1999 03:00:00 GMT |
|
 |
Anders Petre #6 / 7
|
 Help with Comma Delimited File
Danny, try this! ---- snip ---- file=3D'comma.txt' i=3D0 Do While lines(file) row =3D Linein(file) i=3Di+1 Parse Value row With data.i "," data.i.1 "," data.i.2 "," data.i.3 End /* Close the file */ rc=3Dlineout(file) data.0=3Di do i=3D1 to data.0 Say "Record "i Say "Field 1:" data.i Say "Field 2:" data.i.1 Say "Field 3:" data.i.2 Say "Field 4:" data.i.3 Say "------------------------------" End ---- snip ---- And, if you want to remove the ' " ' use row =3D translate(row,'','"') before the parse-statement. /Anders _________________________Reply Header_________________________
Subject: Help with Comma Delimited File 97-01-12 13.24 Hey! Does anyone have some code fragments that can parse this: "Data1_1","Data1_2, ... "DataR_C" "Data2_1","Data2_2, ... etc. Where the data are in a flat file format in rows and columns. Any code fragments would be appreciated. Or tell me where I can go for some. < Please no jokes here. <g> Thank you Danny _+_+_+_+_+_+_+_+_+_+_+_+_+_+ Danny Rubis
LooK Incoporated
+_+_+_+_+_+_+_+_+_+_+_+_+_+_
|
Fri, 02 Jul 1999 03:00:00 GMT |
|
 |
Albert A. Modderkol #7 / 7
|
 Help with Comma Delimited File
How about... fname='YourFile' Call LineIn fname,1,0 Do i=1 while Lines(fname)<>0 recrd=LineIn(fname) Do j=1 while recrd<>'' Interpret 'Parse value recrd with Data'i'_'j 'recrd' End j Interpret 'Data'i'=j-1' End i If you could work with dots instead of underscores, you could replace the Interpret statement with "Parse value recrd with data.i.j recrd" and perform significantky better. Saluti, Albert Quote:
>Hey! >Does anyone have some code fragments that >can parse this: >"Data1_1","Data1_2, ... "DataR_C" >"Data2_1","Data2_2, ... >etc. >Where the data are in a flat file format >in rows and columns. >Any code fragments would be appreciated. >Or tell me where I can go for some. < Please no jokes here. <g> >Thank you Danny >_+_+_+_+_+_+_+_+_+_+_+_+_+_+ >Danny Rubis
>LooK Incoporated
>+_+_+_+_+_+_+_+_+_+_+_+_+_+_
|
Sat, 03 Jul 1999 03:00:00 GMT |
|
|
|