text files with quotes

Jan Decroos jan.decroos at groepvanroey.be
Thu May 16 04:20:01 EDT 2002


Maybe this can help...

the parseItems handler will pass an item to DoStuff only when it's completed
(i.e. when one of the prev. items was started with a quote, all items are
gathered until we find an item ending with a quote, or when there are no
quotes).
Maybe you should strip the leading and the ending spaces too.


-- the button script
on mouseUp
  parseItems cd fld 1   -- my data was in field 1
end mouseUp

on parseItems pData
  repeat for each line lLine in pData
    put empty into lRealItem
    repeat for each item lItem in lLine
      if (char 1 of litem = quote) then
        if (last char of litem = quote) then
          DoStuff lItem
        else
          put lItem into lRealItem
        end if
      else
        if (lRealItem <> empty) then
          put comma&lItem after lRealItem
          if (last char of litem = quote) then
            DoStuff lRealItem
            put "" into lRealItem
          end if
        else
          DoStuff lItem
        end if
      end if
    end repeat
  end repeat
end parseItems

on DoStuff pItem
  answer pItem
end DoStuff


Jan

>Anyone have a good method of parsing a text file that is delimmited by
>commas, yet has quotes (") surrounding SOME of the records, which in turn
>may have commas inside of them (such as a notes field)?  (!)
>
>The only routine I made for this was long and ugly, taking a second per
>record.  I first replaced commas inside of quotes with a blank space, then
>got rid of the quotes, then parsed by comma.
>
>Is there a routine I might be missing?  Thanks!
>
>Mark
>




More information about the use-livecode mailing list