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

Home » Public Forums » archive » Re: extract numbers from 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: extract numbers from string [message #44498] Wed, 22 June 2005 07:29
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Haje Korth writes:

> Pretty clever, I guess I am one of the only IDL programmers out here that is
> not using the execute function.

Yeah, but everything you write, Haje, runs on the VM. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: extract numbers from string [message #44509 is a reply to message #44498] Tue, 21 June 2005 15:20 Go to previous message
Benjamin Hornberger is currently offline  Benjamin Hornberger
Messages: 258
Registered: March 2004
Senior Member
Tobi wrote:
> i have a data file with a header that has several lines, which i read
> with
>
> readf,1,firstline
> readf,1,secondline
> ....
>
> firstline is a string that looks like
> xpixels = 1024
>
> i am trying to convert this to a variable called nx which has the value
> 1024.
>
> is there a clean and easy way to do this?
>

According to the IDL docs, quoted strings can be used only on output,
not on input, so you can't just use a format code. It looks like you
have to cut off "xpixels = " with strmid() and then use fix() or long()
to convert "1024" to a number.

If you explicitly want to make sure the "xpixels = " part is present,
you could use regular expressions, and with them extract the number
(again as a string, then convert to a number).

Benjamin
Re: extract numbers from string [message #44588 is a reply to message #44509] Wed, 22 June 2005 07:24 Go to previous message
Tobi is currently offline  Tobi
Messages: 2
Registered: June 2005
Junior Member
Thanks Ben!

i also just found the STRSPLIT command which i am now using to extract
the number (in my case the number is in the third place).

temp=strsplit(firstline,/extract)
nx=fix(temp[2])
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Color in PLOT(S)??
Next Topic: ISurface issues

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

Current Time: Fri Oct 10 04:47:43 PDT 2025

Total time taken to generate the page: 1.12104 seconds