[progress Communities] [progress Openedge Abl] Forum Post: Re: Reading In Csv Without...

  • Thread starter Thread starter scott_auge
  • Start date Start date
Status
Not open for further replies.
S

scott_auge

Guest
This might help: /* Given a string from import unformatted, return CSV entries in the */ /* 100 extent CSVEntries variable. */ /* TODO: Quotes within a quote is not done */ define input parameter CSVLine as character no-undo. define output parameter CSVEntries as character extent 100 no-undo. define variable CSVLength as integer no-undo. define variable iterator as integer no-undo. define variable extentiterator as integer no-undo. define variable WholeValue as character no-undo. define variable CharValue as character no-undo. define variable LastCharValue as character no-undo. define variable InQuotes as logical initial false no-undo. assign CSVLength = length(CSVLine). do iterator = 1 to CSVLength: assign LastCharValue = CharValue CharValue = substring(CSVLine, iterator, 1) . case CharValue: when "~"" then do: assign InQuotes = not InQuotes. /* flip flop switch */ next. end. /* when " */ when "," then do: if not InQuotes then do: assign extentiterator = extentiterator + 1 CSVEntries[extentiterator] = WholeValue WholeValue = "" . end. /* if not InQuotes */ if InQuotes then assign WholeValue = WholeValue + CharValue. end. /* when , */ otherwise assign WholeValue = WholeValue + CharValue. end. /* case */ end. /* do iterator */ assign CSVEntries[extentiterator + 1] = WholeValue. /*************** Unit test code define variable A as character no-undo. define variable C as character extent 100 format "x(10)" no-undo. A = "345,the word,*,45,~"417,000~",3ed". run /home/sauge/prg/CSVParser.p (input A, output C). /**/ display C. /**/ /* display integer(C[5]). */ *********************************/

Continue reading...
 
Status
Not open for further replies.
Back
Top