[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple number formatting problem

Simon de Vet (simon@mathstat.dal.ca) writes:

> Trivial problem, no doubt, but I've never been able to get my brane
> around formatting options.
> I have a list of files, with the extension .01, .02, .03 ... .12. The
> preceding portion is indentical in all cases.
> I'd like to be able to load these in a loop, but I first need to convert
> the counter value into this format.
> My current, and very ugly, technique is to have an array filled with
> ['01', '02', ... '12'], and then reference the appropriate entry. It
> works, but I don't like it.

I'd try something like this:

   IDL> base = 'myfile'
   IDL> ext = '.dat'
   IDL> for j=1,12 do print, base + String(j, Format="(I2.2)") + ext



David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155