text files with quotes
Geoff Canyon
gcanyon at inspiredlogic.com
Thu May 16 02:34:01 EDT 2002
>David,
>
>Thanks for the response :-)
>
>A sample line in a file I might want to parse:
>1,"5/14/02, 10:00 AM",Pending,Batch0001,"This is a memo field, gee it's
>cool",45362
>
Assuming what you want is:
Remove quotes
Leave commas that are in quotes alone
Replace commas outside of quotes with tab (for instance)
This will do it. Note that this doesn't account for tabs that might exist in the input.
put field "in" into tInputList
put empty into tOutputList
put false into tInQuotes
set the itemDelimiter to quote
repeat for each item I in tInputList
if tInQuotes then
put I after tOutputList
put false into tInQuotes
else
replace "," with tab in I
put I after tOutputList
put true into tInQuotes
end if
end repeat
put tOutputList into field "out"
I tested on 16,000 lines like the one you showed above. On a G3 400 it took about .75 seconds.
--
regards,
Geoff Canyon
gcanyon at inspiredlogic.com
More information about the use-livecode
mailing list