[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Convert Integer to Text
Mark Hadfield wrote:
> From: ""Mark Hadfield"" <m.hadfield@niwa.cri.nz>
>
> > You can add the prefix and suffix via the "+" operator like this...
> >
> > name = 'MC'+string(index,format='(I3.3)')+'.dcm'
> >
> > or within the format specifier like this...
> >
> > name = string(index,format='("MC",I3.3,".dcm"')'
>
> Of course you can also use printf-style format codes (new to IDL 5.4) like
> this
>
> name = string(index,format='(%"MC%3.3d.dcm")')
>
> I suppose there must be somebody out there who actually *uses* this stuff?
>
> ---
> Mark Hadfield
> m.hadfield@niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield
> National Institute for Water and Atmospheric Research
>
> --
> Posted from clam.niwa.cri.nz [202.36.29.1]
> via Mailgate.ORG Server - http://www.Mailgate.ORG
A freind of mine wrote a nice thing for just this application. It's a
function called
padnumstring.pro
here it is
copy all below this line
---------------------------
; Pad 0's at the beginning of a string to make it a
; certain number of characters.
;
; Meant only for integers !
;
function padnumstring, number, length
numstring = strcompress(string(number),/r)
if strlen(numstring) gt length then begin
print,'number is too big !'
stop
end
repeat begin
if strlen(numstring) lt length then numstring='0'+numstring
endrep until strlen(numstring) eq length
return, numstring
end
----------------------------
to above this line
just copy this and name it what I called it.
to make it work put it in a place where you can read idl files
usage:
to get a string from a two digit integer with 5 digits padded with zeros
idl> num = 10
idl> a = padnumstring(num,5)
idl> print,a
a = 00010
Best Dan
--
========================================================================
Daniel Blair Clark University
Nonlinear Dynamics Lab 508-793-7707
950 Main Street blair@nls1.clarku.edu
Worcester, MA 01610-1477 http://nls1.clarku.edu/~blair
========================================================================