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

Home » Public Forums » archive » Re: Splitting An Array Of Strings Without Using Loops
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: Splitting An Array Of Strings Without Using Loops [message #35880 is a reply to message #35875] Thu, 24 July 2003 22:04 Go to previous message
mchinand is currently offline  mchinand
Messages: 66
Registered: September 1996
Member
In article <e5624c04.0307240935.7234e53@posting.google.com>,
Darrick White <darrick.white@med.ge.com> wrote:
> This is probably simple, but I'm having a time trying to figure it
> out. I want to be able to split an array of strings without using
> loops.
>
> Example:
> dataPoints is an array of strings with N elements
> The format of each element within dataPoints is "x:y1:y2:y3:yn". More
> than likely, the data will be in the format of x:y".
>
> This array will become data points (the first element is always
> considered the x coordinate): (x,y) = 1,23. In case of multiple
> points (2:21:34:54), the data will look like: (2,21), (2,34), (2,54).
>
> I need a way to take:
> dataPoints[0] = 1:23
> dataPoints[1] = 2:32
> dataPoints[2] = 3:30
> dataPoints[3] = 4:45
>
>
> and create
> points[2,4]
> 1 23
> 2 32
> 3 30
> 4 45
>
> -Darrick

For the simpler case of just 'x:y' pairs the following show work:

IDL> data=['1:23','2:32','3:30','4:45']

put it into one big string

IDL> datajoin=strjoin(data,':')

IDL> print, datajoin
1:23:2:32:3:30:4:45

Then split it up and reform it into a two by four array

IDL> dataint=reform(fix(strsplit(datajoin,':',/extract)),2,4)
IDL> print, dataint
1 23
2 32
3 30
4 45


Hope that helps,

--Mike

--
Michael Chinander
m-chinander@uchicago.edu
Department of Radiology
University of Chicago
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Reading images from a socket
Next Topic: IDL editor that does text folding

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

Current Time: Sat Oct 11 14:28:49 PDT 2025

Total time taken to generate the page: 0.55991 seconds