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

Home » Public Forums » archive » Re: Chopping up a string
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
Re: Chopping up a string [message #24985] Wed, 09 May 2001 12:30 Go to next message
Amar Nayegandhi is currently offline  Amar Nayegandhi
Messages: 15
Registered: May 2001
Junior Member
"Noam R. Izenberg" wrote:
>
> I have a question about chopping up a string of numbers into seperate inter variables.
>
> I have a set of 5 numbers in a string seprated by spaces (e.g.string= '0 1 2 3 4'), and i need to
> chop them into seperate integer variables (var1=0, var2=1 etc...) I would use the various strmid
> commends exept the size of the numbers is not always the same. Sometimes one or more of the numbers
> will be 2 or more digits. (e.g. '14 14 256 5 2').
>
> Is there any neat trick to doing this?
[
you can use the strsplit keyword in IDL.
e.g: array_of_strings = strsplit(string, /extract) ;the default pattern
to switch at is whitespace
array_of_integers = fix(array_of_strings)
-amar
]

*************************************************
Murphy's Law of Research:
Enough research will tend to support your theory.
*************************************************
Amar Nayegandhi
Graduate Student
Department of Computer Science,
University of South Florida, Tampa.
Re: Chopping up a string [message #24987 is a reply to message #24985] Wed, 09 May 2001 09:29 Go to previous messageGo to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
"Noam R. Izenberg" <noam.izenberg@jhuapl.edu> writes:

> I have a set of 5 numbers in a string seprated by spaces
> (e.g.string= '0 1 2 3 4'), and i need to chop them into seperate
> integer variables (var1=0, var2=1 etc...) I would use the various
> strmid commends exept the size of the numbers is not always the
> same. Sometimes one or more of the numbers will be 2 or more
> digits. (e.g. '14 14 256 5 2').

IDL> string= '0 1 2 3 4'
IDL> vars = long(str_sep(strcompress(string),' '))
IDL> help, vars
VARS LONG = Array[5]
IDL> print, vars

The STRCOMPRESS is optional if you can guarantee a single space
between numbers.

Craig


--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
Re: Chopping up a string [message #25069 is a reply to message #24985] Fri, 11 May 2001 06:09 Go to previous message
Noam R. Izenberg is currently offline  Noam R. Izenberg
Messages: 18
Registered: March 2001
Junior Member
All,

Thanks for the replies on- and off-list. They're just what I needed!

Noam
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: special linux/idl problem
Next Topic: How to plot continuously shaded area?

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

Current Time: Wed Oct 08 13:39:43 PDT 2025

Total time taken to generate the page: 0.00627 seconds