Re: extract numbers from string [message #44498] |
Wed, 22 June 2005 07:29 |
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  |
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  |
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])
|
|
|