comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: IDL string trim
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: IDL string trim [message #61138] Mon, 07 July 2008 07:43 Go to next message
mchinand is currently offline  mchinand
Messages: 66
Registered: September 1996
Member
In article <MPG.22daffe956a87f7598a3cb@news.frii.com>,
David Fanning <news@dfanning.com> wrote:
> RussellGrew writes:
>
>> This may not be the most elegant solution, but you can look at the
>> size of k and add an extra zero to the string manually.
>>
>> eg for the variable 'tmp' being slotted into the filename,
>>
>> if k lt 10. then tmp = '0' + strtrim(string(k), 2) else k =
>> strtrim(string(k), 2)
>>
>> I shall sit here and wait to be shot down by a more elegant solution.
>
> I think this might be the elegant solution you are looking for:
>
> strVal = String(k, Format='(i2.2)')
>
> Cheers,
>
> David

I usually use:

String(k, format='(I02)')

which seems a little more intuitive (the zero indicating to zero-pad the string) but produces the same results as David's.

--Mike


--
Michael Chinander
m-chinander@uchicago.edu
Department of Radiology
University of Chicago
Re: IDL string trim [message #61148 is a reply to message #61138] Sun, 06 July 2008 17:00 Go to previous messageGo to next message
russell.grew is currently offline  russell.grew
Messages: 74
Registered: February 2005
Member
And there it is!

I should really spend some time to understand format codes properly.
Re: IDL string trim [message #61150 is a reply to message #61148] Sun, 06 July 2008 16:15 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
RussellGrew writes:

> This may not be the most elegant solution, but you can look at the
> size of k and add an extra zero to the string manually.
>
> eg for the variable 'tmp' being slotted into the filename,
>
> if k lt 10. then tmp = '0' + strtrim(string(k), 2) else k =
> strtrim(string(k), 2)
>
> I shall sit here and wait to be shot down by a more elegant solution.

I think this might be the elegant solution you are looking for:

strVal = String(k, Format='(i2.2)')

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Re: IDL string trim [message #61151 is a reply to message #61150] Sun, 06 July 2008 15:44 Go to previous messageGo to next message
russell.grew is currently offline  russell.grew
Messages: 74
Registered: February 2005
Member
oop, mistake after the 'else'. Should be 'tmp', not 'k'. Also
spreading it over 2 lines now as google wrapped it up.

if k lt 10. then tmp = '0' + strtrim(string(k), 2) else $
tmp = strtrim(string(k), 2)
Re: IDL string trim [message #61152 is a reply to message #61151] Sun, 06 July 2008 15:42 Go to previous messageGo to next message
russell.grew is currently offline  russell.grew
Messages: 74
Registered: February 2005
Member
This may not be the most elegant solution, but you can look at the
size of k and add an extra zero to the string manually.

eg for the variable 'tmp' being slotted into the filename,

if k lt 10. then tmp = '0' + strtrim(string(k), 2) else k =
strtrim(string(k), 2)

I shall sit here and wait to be shot down by a more elegant solution.
Re: IDL string trim [message #61213 is a reply to message #61138] Tue, 08 July 2008 21:37 Go to previous message
raghuram is currently offline  raghuram
Messages: 32
Registered: February 2008
Member
On Jul 7, 7:43 am, mchin...@midway.uchicago.edu (Mike Chinander)
wrote:
> In article <MPG.22daffe956a87f7598a...@news.frii.com>,
> David Fanning  <n...@dfanning.com> wrote:
>
>
>
>
>
>> RussellGrew writes:
>
>>> This may not be the most elegant solution, but you can look at the
>>> size of k and add an extra zero to the string manually.
>
>>> eg for the variable 'tmp' being slotted into the filename,
>
>>> if k lt 10. then tmp = '0' + strtrim(string(k), 2) else k =
>>> strtrim(string(k), 2)
>
>>> I shall sit here and wait to be shot down by a more elegant solution.
>
>> I think this might be the elegant solution you are looking for:
>
>>   strVal = String(k, Format='(i2.2)')
>
>> Cheers,
>
>> David
>
> I usually use:
>
>      String(k, format='(I02)')
>
> which seems a little more intuitive (the zero indicating to zero-pad the string) but produces the same results as David's.
>
> --Mike
>
> --
> Michael Chinander
> m-chinan...@uchicago.edu
> Department of Radiology
> University of Chicago- Hide quoted text -
>
> - Show quoted text -

Hi all,

Thanks a lot. It works.

Raghu
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: SHA-1, MD5, etc inquiry
Next Topic: Mapping image into a polar-square coordinate

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 14:56:07 PDT 2025

Total time taken to generate the page: 0.00454 seconds