[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string manipulation



In article <on66hxm5tk.fsf@cow.physics.wisc.edu>, craigmnet@cow.physics.wisc.edu writes...
>This is primarily because STRMID and STRPUT are not
>vectorized at all.  Well STRMID *is* vectorized, but not with a sane
>behavior.  For example, what I'd like to do is:
>
>NEWKEY = STRMID(KEY,0,P1) + '50' + STRMID(KEY,P2,100)
>NEWKEY = STRMID(KEY,0,P1) + '50' + STRMID(KEY,P2,100)
>
>Where KEY, P1, and P2 are vectors.  Obviously this doesn't work.  Any
>ideas?

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.    Here is how one
does the example above.

N = N_elements(KEY)
NEWKEY = STRMID(KEY,INTARR(1,N),REFORM(P1,1,N)) + '50' +  $
        STRMID(KEY,REFORM(P2,1,N), REPLICATE(100,1,N) )

I have thought about writing a simple wrapper around STRMID (say STRMIDV) that
would have a simpler syntax for the case of single extractions from
multiple strings.

--Wayne Landsman                         landsman@mpb.gsfc.nasa.gov