reading CSV text file

Stephen Barncard stephenREVOLUTION at barncard.com
Sat Jun 23 00:04:00 EDT 2007


Ahh parsing fun... this is easy...

Rev considers text between quotes as a "word" 
when wholematches is true. Each data within the 
data is on a separate line.

set the wholematches to true
put line 1 of fld "output2" into tLine
repeat for each word tWord in tLine
   put tWord & return after tOut
end repeat
replace quote with empty in tOut

repeat for each line tLN in tOut
   put tLN into tLN2
   if comma is in first character of tLN then delete first character of tLN2
   put tLN2 & return after tOut2
end repeat

put tOut2 into fld "output"

-------------------------------fld output-------------------------
7722


Fuji
Cleaning
Cartridge
für
DLT
Streamer,
retail,DLT
Reinigungskassette
für
bis
zu
20
Reinigungen
nicht
für
DLT
1
und
VS!,,,BAND,183,Diverse
Hersteller,42419,31.03,38.79,35.27,34.48,34.48,34.48,32.66,0.000,0.000,,24
----------------------------------------------------------------------------



>Hi,
>
>i have to read a textfile, which is comma 
>separated and contains " as text identifier. The 
>item delimiter is ,
>My problem is, i do not know, how can i read the 
>file and detect each item of a line, as the 
>items are sepearated by comma and the 
>textfield/items could contain comma, too. How 
>can i tell Revolution to ignore the comma in the 
>"tesxtarea of an item"
>
>Here´s an example line
>
>"7722"," ","Fuji Cleaning Cartridge für DLT 
>Streamer, retail","DLT Reinigungskassette für 
>bis zu 20 Reinigungen nicht für DLT 1 und 
>VS!","","","BAND","183","Diverse 
>Hersteller","42419",31.03,38.79,35.27,34.48,34.48,34.48,32.66,0.000,0.000,"",24
>
>As you can see, some fields/items are included 
>in " ,others (the numeric values) are not. The 
>field included in " could contain , .
>
>Any idea, how i can solve that. I have to 
>mention that in the textfields/items there could 
>be also the " as product description e.g.  TFT 
>19"  or HDD 2.5"
>
>
>Regards,
>
>Matthias

-- 


stephen barncard
s a n  f r a n c i s c o
- - -  - - - - - - - - -





More information about the use-livecode mailing list