Porvided below is an example of using ;: for parsing CSV files. The
variable sj
is defined twice (once in the way I would normally define it in a script and
once in a more verbose manner for clarity)

fa =. a. #~ # }. [: -. [: -. [: ~: a. ,~ ]

sj =. 7 5 2 $ 0 0 1 1 2 1 3 1 4 1 0 0 1 0 2 2 1 0 1 0 0 0 1 1 1 2 3 1 4 1 0
0 3 0 3 0 5 0 3 0 0 0 4 0 4 0 4 0 6 0 0 0 0 0 2 2 3 0 0 0 0 0 0 0 2 2 0 0 4
0

sj =. _2] \"1 }.".;._2  (0 : 0)
NB.    X    C    D    Q    S
      0 0  1 1  2 1  3 1  4 1        NB. 0 - Other
      0 0  1 0  2 2  1 0  1 0        NB. 1 - Char
      0 0  1 1  1 2  3 1  4 1        NB. 2 - Delim
      0 0  3 0  3 0  5 0  3 0        NB. 3 - Quote
      0 0  4 0  4 0  4 0  6 0        NB. 4 - SQuote
      0 0  0 0  2 2  3 0  0 0        NB. 5 - Second Quote
      0 0  0 0  2 2  0 0  4 0        NB. 6 - Second SQuote
)

mj =. <'';(fa ',"''');',';'"';''''

csv_parser =. (0;sj;mj)&;:

   csv_parser 'Year,"Make,Model",''foo,bar'',Hello,World'
┌────┬────────────┬─────────┬─────┬─────┐
│Year│"Make,Model"│'foo,bar'│Hello│World│
└────┴────────────┴─────────┴─────┴─────┘
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to