SC> What's the best way to add leading zeros to a set of integers.

The compatible way, going back to J Version 5, 1992:

Over-take from the end with {. and Fit !. it to specify the fill
element:

   _4 {.!.'0'   'ab'
00ab

Apply the usual extra stuff to have that work on your numeric list:

   _4&({.!.'0')@":"0 a
0001
0002
0003
0004
0005
0010
0020
0030
[...]

The new way, avalailable since J Release 6.01, 2006:

   'r<0>4.0'  8!:2  ,. a

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

Reply via email to