[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to convert (concatenate) a string array to a string scalar?
- Subject: Re: How to convert (concatenate) a string array to a string scalar?
- From: Alex Schuster <alex(at)pet.mpin-koeln.mpg.de>
- Date: Mon, 13 Mar 2000 19:02:15 +0100
- Newsgroups: comp.lang.idl-pvwave
- Organization: Regional Computing Center, University of Cologne
- References: <38CCFBD8.8FB9342F@risoe.dk> <MPG.1336b0b12655360989a8b@news.frii.com>
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:18909
David Fanning wrote:
> Kristian Kjaer (kristian.kjaer@risoe.dk) writes:
>
> > Given
> > numarray=[1342,1347,1355] ;, say, I wan't
> > strscalar='1342,1347,1355' ;, but
> > help,string(numarray)
> > gives: STRING = Array[3]
> > and
> > help,total(string(numarray))
> > gives an error.
> >
> > How to convert (concatenate) a string array to a string scalar?
>
> Now here (I feel pretty darn confident) is the perfect
> opportunity to use a loop in IDL. :-)
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.
Alex
--
Alex Schuster Wonko@weird.cologne.de PGP Key available
alex@pet.mpin-koeln.mpg.de