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 #28082] Tue, 20 November 2001 21:32 Go to previous message
Chad Bahrmann is currently offline  Chad Bahrmann
Messages: 7
Registered: September 2001
Junior Member
Thanks for the headstart...I believe I have something that works....
The function I have written below gives:
IDL> x=[1,2,3,5,6,7,9,45,46,47,48,49,50,51,56,59]
IDL> print, time2str(x)
% Compiled module: TIME2STR.
1-3,5-7,9,45-51,56,59

function time2str, x
dx=(x-shift(x,1))[1:*]
l=where(dx ne 1)
times=''
nl=n_elements(l)
nx=n_elements(x)
if l[0] eq -1 then times='0-59' else begin
if l[0] eq 0 then times=strtrim(string(x[0]),2)+','
if l[0] ne 0 then
times=strtrim(string(x[0]),2)+'-'+strtrim(string(x[l[0]]),2) +','
for i=0, nl-2 do begin
if ((l[i+1]-l[i]) gt 1) then begin
times=times+strtrim(x[l[i]+1],2)+'-'+strtrim(x[l[i+1]],2)+', '
endif else begin
times=times+strtrim(x[l[i+1]],2)+','
endelse
endfor
if (nx-1)-l[(nl-1)] eq 1 then times=times+strtrim(string(x[nx-1]),2) else
$
times=times+strtrim(x[(l[nl-1])+1],2)+'-'+strtrim(string(x[n x-1]),2)
endelse
return, times
END

"Chad Bahrmann" <cbahrmann@ou.edu> wrote in message
news:v8CK7.6670$o4.14684@news.ou.edu...
> 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
>
>
[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 02:11:39 PDT 2025

Total time taken to generate the page: 1.67972 seconds