comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » How to convert (concatenate) a string array to a string scalar?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
How to convert (concatenate) a string array to a string scalar? [message #19283] Mon, 13 March 2000 00:00 Go to next message
Kristian Kjaer is currently offline  Kristian Kjaer
Messages: 58
Registered: June 1998
Member
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?

Thanks for any help,
Kristian Kj�r.
Re: How to convert (concatenate) a string array to a string scalar? [message #19415 is a reply to message #19283] Tue, 14 March 2000 00:00 Go to previous message
John-David T. Smith is currently offline  John-David T. Smith
Messages: 384
Registered: January 2000
Senior Member
Mike Fitzgibbon wrote:
>
> In article <38CD6DA1.6E45DF18@astro.cornell.edu>,
> J.D. Smith <jdsmith@astro.cornell.edu> wrote:
>> 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)])

> Why not just use the format termination code:
>
> s = string(a,format='('+strtrim(n_elements(a))+'(I0,:,","))')
>
> (Coincidentally, I happened to need to do this this morning)

Because it's not nearly obfuscated enough. And Alex already did that one.

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 |*|
Re: How to convert (concatenate) a string array to a string scalar? [message #19419 is a reply to message #19283] Mon, 13 March 2000 00:00 Go to previous message
mikef is currently offline  mikef
Messages: 9
Registered: May 1998
Junior Member
In article <38CD6DA1.6E45DF18@astro.cornell.edu>,
J.D. Smith <jdsmith@astro.cornell.edu> wrote:
> 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 |*|

Why not just use the format termination code:

s = string(a,format='('+strtrim(n_elements(a))+'(I0,:,","))')

(Coincidentally, I happened to need to do this this morning)
--
Mike Fitzgibbon MRFitz@ns.arizona.edu
UofAz, LPL phone:(520)626-4791
Systems Programmer, Pr. fax: (520)621-6783
Mars Surveyor '98: TEGA
Mars Orbiter 2001: GRS
--
--
Mike Fitzgibbon MRFitz@ns.arizona.edu
UofAz, LPL phone:(520)626-4791
Systems Programmer, Sr. fax: (520)621-6783
Re: How to convert (concatenate) a string array to a string scalar? [message #19420 is a reply to message #19283] Mon, 13 March 2000 00:00 Go to previous message
John-David T. Smith is currently offline  John-David T. Smith
Messages: 384
Registered: January 2000
Senior Member
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 |*|
Re: How to convert (concatenate) a string array to a string scalar? [message #19424 is a reply to message #19283] Mon, 13 March 2000 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
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.

:-(

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: How to convert (concatenate) a string array to a string scalar? [message #19425 is a reply to message #19283] Mon, 13 March 2000 00:00 Go to previous message
Alex Schuster is currently offline  Alex Schuster
Messages: 124
Registered: February 1997
Senior Member
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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Release of IDL 5.3.1 for Microsoft Windows 95/98/NT/2000
Next Topic: SVDFIT bug?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:14:16 PDT 2025

Total time taken to generate the page: 0.00760 seconds