Re: Dealing with list created by STRSPLIT? [message #76182 is a reply to message #76181] |
Fri, 20 May 2011 07:20   |
BLesht
Messages: 89 Registered: March 2007
|
Member |
|
|
On May 20, 7:02 am, Haje Korth <hajeko...@gmail.com> wrote:
> Maybe i am missing something. STRSPLIT returns an array of string when
> using the /extract keyword. You simply access the elements by using
> [], splitnames[0]='diskname', etc. Haje
>
> On May 19, 10:44 pm, Barry Lesht <ble...@gmail.com> wrote:
>
>> I have an array of full-path filenames from which I need to extract
>> some substrings. The array consists of a large number of strings of
>> the form
>
>> diskname/maindir/subdir1/subdir2/subdir3/filename
>> diskname/maindir/subidr1/subdir2/subdir3/filename etc.
>
>> The lengths of the subdirXs can be different. What I wanted to do was
>> create some arrays the elements of which would be the subdirXs. I
>> thought this would be simple now that STRSPLIT allows arrays as
>> input. I had the array of n filenames in a string array and I used
>
>> splitnames = STRSPLIT(filenames, '/', /EXTRACT).
>
>> The result 'splitnames' is a list with n elements and each element is
>> of the form
>
>> diskname maindir subdir1 subdir2 subdir3 filename as it should be.
>> Each element is a string array.
>
>> What I can't seem to figure out is how to now extract one of these
>> terms from the list element. That is, I'd like to end up with arrays
>> that have the n subdir2s (for example). I've tried using the
>> LIST::TOARRAY () feature but this fails for some mysterious reason
>> with the message
>
>> IDL> namearray=splitnames.ToArray()
>> % LIST::TOARRAY: Unable to convert to type STRING: Element 798
>> % Error occurred at: LIST::TOARRAY
>> % $MAIN$
>> % Execution halted at: $MAIN$
>
>> Element 798 is no different from any of the elements in the list, by
>> the way, but this is not the real problem (at least I don't think it
>> is)
>
>> There must be an easy way to do this; I'm not seeing it. Any help
>> would be much appreciated.
>
>
Thanks, Haje. Maybe I'm being especially dense this morning, but I
don't understand your suggestion. Indeed, the elements of list
splitnames are string arrays, and, for each individual list element
(e.g. splitnames[0] ) I could use WHERE to determine the array element
that matches my selection criterion (e.g. disk2s = WHERE(splitnames[0]
EQ 'disk2'), but that doesn't solve my problem. Maybe my initial post
wasn't clear. For example, if I start with an array of filenames
a1/b1/c1/d1/e1
a1/b1/c2/d1/e2
a1/b1/c2/d2/e3
a1/b1/c2/d3/e4 etc.
Using STRSPLIT results in a list
a1 b1 c1 d1 e1
a1 b1 c2 d1 e2
a1 b1 c2 d2 e3
a1 b1 c2 d3 e4 etc.
and what I want is something like like c2s = WHERE({third element of}
splitnames[*] EQ 'c2') that will return an array of the list element
numbers that include 'c2'. I think I need to play with WHERE and some
of the other string processing routines.
|
|
|