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

Home » Public Forums » archive » Re: string functions and arrays
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: string functions and arrays [message #50551] Wed, 11 October 2006 11:01 Go to next message
news.verizon.net is currently offline  news.verizon.net
Messages: 47
Registered: August 2003
Member
greg michael wrote:
> Isn't it odd that STRMID can't operate on a string array? I can get a
> nice set of positions from an array with STRPOS, but can't apply them
> like this...
>
STRMID does operate on string arrays but with a funky syntax. You
can search on "strmid" and "vector" in the archives to see previous
posts on the topic but I'll quote from myself.

"The problem when STRMID was vectorized for V5.3 was that it was made
*too* powerful -- it handles simultaneously both extraction from
multiple strings and multiple extractions from a single string. In
practice, I think the first situation -- extraction from multiple
strings -- is far more common, but has an ugly syntax in the current
STRMID implementation.

The online help describes the vector use of STRMID this way:

"If First_Character or Length is an array, the size of their first
dimension determines how many substrings are extracted from each
element of Expression. We call this the "stride". If both are arrays,
they must have the same stride. If First_Character or Length do not
contain enough elements to process Expression, STRMID automatically
loops back to the beginning as necessary. Excess values are ignored. If
the stride is 1, the result will have the same structure and number of
elements as Expression. If it is greater than 1, the result will have
an additional dimension, with the new first dimension having the same
size as the stride. "

In your example, the call to strmid() needs to be (if there are Npts
values in your array)
strmid(lbl, 0, reform(p-1, 1, npts))

I've thought about writing a wrapper to strmid() that provides an easy
syntax for the common case of single extractions from multiple strings,
but in practice I usually use
http://idlastro.gsfc.nasa.gov/ftp/pro/misc/gettok.pro
to extract strings, (and this includes a vector call to strmid()
internally). --Wayne
Re: string functions and arrays [message #50735 is a reply to message #50551] Wed, 11 October 2006 14:47 Go to previous message
greg michael is currently offline  greg michael
Messages: 163
Registered: January 2006
Senior Member
Thanks, Wayne. I read through that paragraph at least three times
before I posted - I'd decided that whatever it was that it might mean,
it couldn't be what I was looking for. After seeing your solution, it
took me more than another three readings to grasp what it was that
you'd done!

Anyway, I'm glad there is a solution. I think it can be written even
more simply as:

strmid(lbl, 0, transpose(p-1))

and

strmid(lbl, transpose(p+1))

which, after all, I don't find such a bad syntax. An example in the
documentation could have been useful...

thanks again,
Greg
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: idl syntax validation
Next Topic: _extra

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

Current Time: Wed Oct 08 18:40:01 PDT 2025

Total time taken to generate the page: 0.00633 seconds