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

Home » Public Forums » archive » Re: converting int array to 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 int array to a string [message #28084 is a reply to message #28082] Tue, 20 November 2001 17:11 Go to previous messageGo to previous message
Richard French is currently offline  Richard French
Messages: 173
Registered: December 2000
Senior Member
Chad Bahrmann wrote:
>
> Is there an easy way to convert the following:
>
> x=[1,2,3,4,5,17,45,46,47,48,49,50,51,59]
> where x is minutes in an hour for example
>
> to a string like:
>
> minutes='1-5,17,45-51,59'
>
> Thanks in advance,
>
> Chad Bahrmann

Chad - Not that I know of, but I think I have hacked something
together before using the shift operator to tell you which elements
are adjacent. For example:

x=[1,2,3,4,5,17,45,46,47,48,49,50,51,59]

dx=(x-shift(x,1))[1:*]
print,dx
1 1 1 1 12 28 1 1 1 1 1 1
8
; then you can figure out which ones require special attention:

l=where(dx ne 1)
; the following prints the last element in a seqeuence that can be
; connected by a hyphen
print,x[l]

; but I think that handling all the special cases could be a nightmare!
Post your best solution! This is offered as just a start.
Dick French
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Use SlickEdit to write and compile IDL programs
Next Topic: Structure assign question

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

Current Time: Fri Oct 10 12:48:48 PDT 2025

Total time taken to generate the page: 0.56047 seconds