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

Home » Public Forums » archive » Re: converting a vector into a string
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: converting a vector into a string [message #45900] Thu, 20 October 2005 15:27 Go to previous message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
R.G. Stockwell wrote:
> "Francois L." <fleduc@lycos.com> wrote in message
> news:1129837956.424479@news.drenet.dnd.ca...
>> Sorry, I am reposting this message again because the previous one
>> contained many errors in the header...
>>
>> I have a vector A (integers):
>>
>>> A = [1,2,3,4]
>>
>> that I want to convert into a string.
>>
>> If I use the command
>>
>>> B = string(A)
>>
>> then B is a string of four elements.
>>
>> How can I convert A to string in order to have '1234' ? which is not an
>> array of four elements...
>>
>> Well at the end, I want to convert '1234' into the number 1234.
>>
>
>
> IDL> help,long(strcompress(strjoin(string([1,2,3,4])),/rem))
>
> <Expression> LONG = 1234

Cool. I was not aware of STRCOMPRESS. It seems it's been in IDL since
the beginning, whereas I've only been using IDL since 1992!

Looking again at the original poster's last sentence, I wonder if
conversion to and from strings isn't an unnecessary detour. He is
starting with integer array [1,2,3,4] and wants to end up with decimal
integer 1234. So perhaps his problem can be interpreted as "convert a
vector of integers (all presumably between 0 and 9) to a number on the
assumption that the elements of the vector represent the digits of the
number in decimal form". If so I suggest

IDL> a = [1,2,3,4]
IDL> help, total(a*10^reverse(lindgen(n_elements(a))), /INTEGER)
<Expression> LONG64 = 1234


--
Mark Hadfield "Kei puwaha te tai nei, Hoea tahi tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Call External Error
Next Topic: Re: Call External Error

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

Current Time: Sun Oct 12 00:41:45 PDT 2025

Total time taken to generate the page: 0.48259 seconds