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

Home » Public Forums » archive » Re: String Spliting
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: String Spliting [message #49354 is a reply to message #49353] Wed, 19 July 2006 12:49 Go to previous messageGo to previous message
mmiller3 is currently offline  mmiller3
Messages: 81
Registered: January 2002
Member
>>>> > ChristopherFlorio <ChristopherFlorio@gmail.com> writes:

> I am having a problem with the STRSPLIT function. I am
> using it to extract the file extension from a string where
> it might not be at the end. However in the process I am
> also eliminating addition elements, not found in the
> extension. For example

> file='Image.img' filter='*.img'

> file=STRJOIN(STRSPLIT(file,filter,/EXTRACT))

> file='Iae'

> desired output: file='Image'

The pattern argument to strsplit is either a single character, or
a regular expression. You are using '*.img' as a regular
expresion and therefore are splitting on any string that looks
like zero or more characters followed by i, m or g. If you want
to split in the '.', use '.' as your split: strsplit(file, '.',
/extract)

IDL> print, (strsplit('Image.img', '.', /extract))[0]
Image

If you want to strip off the extension, you can use strmid and
strpos. (Reverse_search is handy for gettign the last match,
rather than the first)

IDL> file='Image.img'
IDL> print, strmid(file, 0, strpos(file,'.', /reverse_search))
Image
IDL> file='Image.with.multiple.periods.img'
IDL> print, strmid(file, 0, strpos(file,'.'))
Image
IDL> print, strmid(file, 0, strpos(file,'.', /reverse_search))
Image.with.multiple.periods


Mike
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Surface plots in spherical coordinates
Next Topic: Re: mpfitexpr using functargs

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

Current Time: Sun Oct 12 14:52:58 PDT 2025

Total time taken to generate the page: 1.12200 seconds