num =: *./@(e.&'0123456789_.abdejprx')
map =: ('-',a.) {~ ('_',a.) i. ]
msign=: map^:num&.>
x=: 2 5 $ ;:'foo _upon th-ee _123 foo_13 abjec_44 _1.23e_45j_6.7e_8 __'
(msign -: csvminus) x
1
Note that you can also use the new 8!:n facility to
do numeric formatting. 8!:n uses - instead of _ by default.
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, February 15, 2006 4:41 PM
Subject: [Jprogramming] Minus sign when using writecsv
Dear all,
I find the low-slung J minus sign a nuisance outside J, as I imagine do other
J users, and would like to have a conversion from'_' to '-' built into
writecsv
in some future release.
For the present, I apply the following script to a boxed 'characterised'
table
that is ready to be submitted to writecsv:
csvminus =:3 : 0 NB. Replaces negative '_' with '-' within an individually
boxed
shape=.$y. NB. "characterized" table prepared for output by writecsv
numbers=.'0123456789_.abdejprx'
listboxes=.,y.
new=.0$0
while.0<#listboxes
do. current=.>{.listboxes
listboxes=.}.listboxes
new=.new,<current
if. -.(*./current e.numbers)
do. continue
elseif. '_'={.current
do. new=.(}:new),<'-',}.current
end.
end.
shape $ new
)
If anyone can do this more elegantly, I would be happy to follow their lead
but would add that mine works for 4-dimensional output tables, which I need
quite often.
C J Teather
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm