Re: strmid() [message #46904] |
Thu, 12 January 2006 01:08 |
Liberum
Messages: 48 Registered: September 2005
|
Member |
|
|
Hi David,
Yes, your script is exactly what I needed. Thanks! Now I don't have to
reinvent the wheel!
Super!
Sheldon
|
|
|
Re: strmid() [message #46920 is a reply to message #46904] |
Wed, 11 January 2006 07:10  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Sheldon writes:
> One more question David,
>
> My goal was to take the name of a file that may have varying lengths
I don't understand the question, sorry. :-(
Maybe you want something like FSC_BASE_FILENAME, which
can parse a filename into the base name, the directory,
and its file extension:
IDL> file = 'some_ordinaryfile.h5'
IDL> name = FSC_Base_Filename(file, Directory=d, Extension=e)
IDL> Print, e
h5
IDL> file = 'some_ordinaryfile.hdf'
IDL> name = FSC_Base_Filename(file, Directory=d, Extension=e)
IDL> Print, e
hdf
You can find it here.
http://www.dfanning.com/programs/fsc_base_filename.pro
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
|
Re: strmid() [message #46923 is a reply to message #46922] |
Wed, 11 January 2006 06:31  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Sheldon writes:
> Can someone check this out and explain it to me becuase I don't get it
> at all:
> **********************************************
> a = "some_ordinaryfile.h5"
> IDL> print, strmid(a,0,2,/reverse_offset)
> 5
> IDL> print, strmid(a,0,3,/reverse_offset)
> 5
> IDL> print, strmid(a,0,1)
> s
> IDL> print, strmid(a,0,2)
> so
> IDL> print, strmid(a,0,3)
> som
> IDL>
> Now according to the instruction book the keyword: REVERSE_OFFSET
> forces IDL to start counting from the end of the file so it should work
> like this:
> print, strmid(a,0,2,/reverse_offset)
> h5
Reverse_Offset means that instead of counting from the
left, you now count from the right. It doesn't have
anything to do with which direction the LENGTH is
taken in. The length is always counted in the direction
to the right of the starting point.
So, if you position yourself to the right of your string
and take an offset of 0, you position yourself at the
"5". No matter what length you ask for, there is only
one character to read from that position.
What you want is this:
IDL> Print, strmid(2,3, /reverse_offset)
.h5
You were thinking of offsets as if we had reversed the
string. But, of course, we can't do that unless we want
to also start reading text right to left. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|