---Peter Lemenkov wrote:
> I need to read and split csv-data. If I try to convert data using ;:
> verb, then I've got the following:
>
>    Csv =: '27.08.2001,19:30,0.9117,0.9123,0.9109,0.9118,227'
>    ;: Csv
> +----------+-+---+--+-+------+-+------+-+------+-+------+-+---+
> |27.08.2001|,|19:|30|,|0.9117|,|0.9123|,|0.9109|,|0.9118|,|227|
> +----------+-+---+--+-+------+-+------+-+------+-+------+-+---+

Hi Peter,
To split/parse the string Csv above, the best way is probably to use the 
primitive cut ;.

Where ;. cuts the string, depends on the form

<;.1  will cut and box the string on the first occurring character in the 
string.
<;.2 will cut and box the string on the last occurring character in the string.
<;._1 will cut and box the string on the first occurring character & remove 
that character
<;._2  and so on.

You want to cut on ',' so you need to add a comma to the start or end of your 
string.

   <;.2 Csv,','
+-----------+------+-------+-------+-------+-------+----+
|27.08.2001,|19:30,|0.9117,|0.9123,|0.9109,|0.9118,|227,|
+-----------+------+-------+-------+-------+-------+----+

   <;._2 Csv,','
+----------+-----+------+------+------+------+---+
|27.08.2001|19:30|0.9117|0.9123|0.9109|0.9118|227|
+----------+-----+------+------+------+------+---+

You could build on this technique to cut on line feeds (LF) first & then on ','.

However if you are wanting to read CSV files or strings then you are probably 
best to use the tables/csv addon. 
<http://www.jsoftware.com/jwiki/Addons/tables/csv>

Ric
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to