Re: Another strsplit question [message #37759 is a reply to message #37747] |
Tue, 20 January 2004 12:49  |
MKatz843
Messages: 98 Registered: March 2002
|
Member |
|
|
kneller@nist.gov (Larry Kneller) wrote in message news:<96e91d8d.0401200800.34fa60fa@posting.google.com>...
> Most functions in IDL will operate on arrays.
> Is there a way to make strsplit allow this?
>
> e.g.
> s = ['I see the computer.','I am typing a message.',$
> 'This is the idl-pvwave newsgroup.']
>
> segs = strsplit(s,/extract,/some_option)
>
> print,segs[0,0],segs[1,0],segs[2,0],segs[2,4]
>
> RESULT WOULD BE:
>
> I I This newsgroup.
The difficulty here is that since every input string is different,
every row of the output array will want to have a different number of
values. So it's ambiguous how you'd write it. Would you look for the
row with the most elements and make all rows be that long? That's one
way. Or would you have the output be a pointer array where each
element points to an array of strings. That's probably more memory
efficient in the long run, but some people might not like dealing with
pointers, and you'd run the risk of asking for array elements that
don't exist.
Looks like you need to write your own function here to fit your needs.
That's pretty straightforward to do in a case like this.
M. Katz
|
|
|