STRMID question [message #26279] |
Mon, 20 August 2001 10:13  |
Paul van Delst
Messages: 364 Registered: March 1997
|
Senior Member |
|
|
Hello,
I have a "question" about the output of STRMID. Consider the following:
Given an input string array:
IDL> s='_'+strtrim(10L^lindgen(10),2)+'.'
IDL> print, s
_1. _10. _100. _1000. _10000. _100000. _1000000. _10000000. _100000000. _1000000000.
I search for the "_" and "." characters (I do a reverse search as there may be other "_"
or "." in the string before the last set):
IDL> delim1 = STRPOS( s, '_', /REVERSE_SEARCH ) + 1
IDL> delim2 = STRPOS( s, '.', /REVERSE_SEARCH ) - 1
So now I want to extract out the substrings from the string array delimited by delim1 and
delim2:
IDL> help, STRMID( s, delim1, delim2-delim1+1 )
<Expression> STRING = Array[10, 10]
How come I get a 2-D array output? I can sort of see how that _could_ happen since delim1
and delim2 are both vectors so the output:
IDL> print, STRMID( s, delim1, delim2-delim1+1 )
1 1. 1. 1. 1. 1. 1. 1. 1. 1.
1 10 10. 10. 10. 10. 10. 10. 10. 10.
1 10 100 100. 100. 100. 100. 100. 100. 100.
1 10 100 1000 1000. 1000. 1000. 1000. 1000. 1000.
1 10 100 1000 10000 10000. 10000. 10000. 10000. 10000.
1 10 100 1000 10000 100000 100000. 100000. 100000. 100000.
1 10 100 1000 10000 100000 1000000 1000000. 1000000. 1000000.
1 10 100 1000 10000 100000 1000000 10000000 10000000. 10000000.
1 10 100 1000 10000 100000 1000000 10000000 100000000 100000000.
1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000
sort of makes sense, but does it make sense to anyone that it _should_ happen?? It's not a
big deal since I can do a
IDL> si=STRMID( s, delim1, delim2-delim1+1 )
IDL> i=indgen(10)
IDL> print, si[i,i]
1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000
to extract the diagonal, but the original result sorta threw me and I haven't yet
recovered <whimper>.
paulv
--
Paul van Delst A little learning is a dangerous thing;
CIMSS @ NOAA/NCEP Drink deep, or taste not the Pierian spring;
Ph: (301)763-8000 x7274 There shallow draughts intoxicate the brain,
Fax:(301)763-8545 And drinking largely sobers us again.
Alexander Pope.
|
|
|