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

Re: How to convert (concatenate) a string array to a string scalar?



David Fanning wrote:
> 
> Alex Schuster (alex@pet.mpin-koeln.mpg.de) writes:
> 
> > BEEEEEP! There's no need for that, here's a function which does what
> > Kristian wants:
> >
> > function strconcat, numarray
> >   format = string( '(', n_elements( numarray ), '(I0,', '","))' )
> >   str = string( numarray, format=format )
> >   return, strmid( str, 0, strlen( str ) - 1 )
> > end
> >
> > In the example above, the format string which is created inside the
> > function would be '3(I0,",")' , which tells the STRING routine to take
> > three integers and add them to the string without leading blanks, but
> > with a comma between them. The last strmid call only removes the last
> > comma from the string.
> 
> I only know one thing for certain about IDL, and that
> is this:
> 
>    There is an inverse correlation between how certain
>    I am that something can only be done one way in IDL
>    and the number of alternative methods I will learn
>    about in the next 15 minutes.
> 
> :-(

Obfuscated IDL Contest Entry:

s=string((reform((tmp=byte(strtrim(a,2)+[replicate(",",n_elements(a)-1),""])),$
		n_elements(tmp)))[where(tmp ne 0)])


Given integer array "a".

JD

-- 
 J.D. Smith                             |*|      WORK: (607) 255-5842    
 Cornell University Dept. of Astronomy  |*|            (607) 255-6263
 304 Space Sciences Bldg.               |*|       FAX: (607) 255-5875 
 Ithaca, NY 14853                       |*|