Re: Appending Numbers to Strings in IDL [message #48976] |
Tue, 06 June 2006 10:08 |
Jo Klein
Messages: 54 Registered: January 2006
|
Member |
|
|
> But, that leaves a lot of whitespace in front of the number. Is there
> a way to eliminate this whitespace?
Hi Branch,
You can specify a FORMAT keyword to STRING to get the numbers prettily
formatted. If you just want integers without whitespace, try
string(variable,FORMAT='(I0)')
This is a very flexible approach - with FORMAT, you could also specify
the precision of floating point numbers and the like.
Jo
|
|
|
|
Re: Appending Numbers to Strings in IDL [message #48988 is a reply to message #48987] |
Mon, 05 June 2006 14:59  |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
steve wrote:
> Hey Todd,
> You just need to use StrTrim to get rid of the leading spaces. So when
> you create your string you would do it like this:
> name + StrTrim(string(variable),2)
And, as an added bonus, you can even eliminate the string(). Strtrim does it fer free! :o)
IDL> i=1
IDL> print,'>',i,'<'
> 1<
IDL> print,'>',strtrim(i,2),'<'
>1<
paulv
--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx
Ph: (301)763-8000 x7748
Fax:(301)763-8545
|
|
|
Re: Appending Numbers to Strings in IDL [message #48989 is a reply to message #48988] |
Mon, 05 June 2006 14:57  |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
toddbranch wrote:
> Hi everyone,
>
> I'm new to IDL, and have only been using it for two weeks. I bought
> Liam Gumley's book and it has been quite helpful so far. The program
> I'm writing requires me to identify different objects within an image.
> Since there may be more than one, I append a variable number to the end
> of the file name string to differentiate between objects.
>
> I know that you can append numbers to a string like this:
> string+string(variable)
>
> But, that leaves a lot of whitespace in front of the number. Is there
> a way to eliminate this whitespace?
> I want it to work like this:
> string+string(variable)=stringvariable, not string variable
you can do
stringvar+strtrim(variable,2)
with variable = 1, 2, 3, 4,...... to give you something like
blah1
blah2
blah3
...
blah10
...
blah127
...etc
or
stringvar+string(variable,format='(i4.4)')
to do stuff like
blah0001
blah0002
blah0003
...
blah0010
...
blah0127
...etc
In the latter case, variable must be < 10000.
paulv
--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx
Ph: (301)763-8000 x7748
Fax:(301)763-8545
|
|
|
Re: Appending Numbers to Strings in IDL [message #48990 is a reply to message #48989] |
Mon, 05 June 2006 14:54  |
steve
Messages: 19 Registered: March 1991
|
Junior Member |
|
|
Hey Todd,
You just need to use StrTrim to get rid of the leading spaces. So when
you create your string you would do it like this:
name + StrTrim(string(variable),2)
Hope that helps,
Steve
toddbranch wrote:
> Hi everyone,
>
> I'm new to IDL, and have only been using it for two weeks. I bought
> Liam Gumley's book and it has been quite helpful so far. The program
> I'm writing requires me to identify different objects within an image.
> Since there may be more than one, I append a variable number to the end
> of the file name string to differentiate between objects.
>
> I know that you can append numbers to a string like this:
> string+string(variable)
>
> But, that leaves a lot of whitespace in front of the number. Is there
> a way to eliminate this whitespace?
> I want it to work like this:
> string+string(variable)=stringvariable, not string variable
>
> Thanks a lot for your help,
>
> Branch
|
|
|