Vectorized STRMID ( was Re: Selecting odd/even numbered files) [message #30055] |
Wed, 03 April 2002 12:37 |
Wayne Landsman
Messages: 117 Registered: January 1997
|
Senior Member |
|
|
David Fanning wrote
> where I was trying to use the slen array to select a different
> length for each possible filename (assuming they weren't
> all the same length, but that they all had 3 character
> extensions). In that case, the numbers variable kept
> coming out as a 4x4 element array, rather than the expected
> 4-element array.
To extract the last 3 characters of a string array with arbitary
(non-indentical) lengths, I'd use the
reverse_offset keyword and count from the end.
numbers = fix(strmid(files,2,3,/reverse))
The reason you were getting 4x4 output arrays is that the vectorized STRMID is
sometimes *too* powerful -- it can both extract many substrings from a single
string, and extract substrings from many strings. Therefore, the position
parameter has to be REFORMed into a 2-d array. So to do the vectorized
extraction without the /reverse keyword...
n = N_elements(files)
len = reform( strlen(files), 1, n)
numbers = fix( strmid( files, len-3, 3))
Cheers, --Wayne
landsman@mpb.gsfc.nasa.gov
|
|
|