Re: extracting numbers [message #48026] |
Thu, 23 March 2006 08:06 |
Norbert Hahn
Messages: 46 Registered: May 2003
|
Member |
|
|
kl_tah@hotmail.com wrote:
> Hi, does anyone happen to know how to extract a sequence of numbers
> (including the sign) between two characters? for eg. I have
>
> AAAA = -23.445 /BBBBB
> and could like to extract the number between '=' and '/'
>
> cheers,
Depending on the positions in the string you may as well _read_ from a
string using the procedure reads:
buffer = "AAAA = -23.445 /BBBBB"
reads, buffer, z, format='(6x,f8.3)'
help, z
Z FLOAT = -23.4450
HTH
Norbert
|
|
|
Re: extracting numbers [message #48028 is a reply to message #48026] |
Thu, 23 March 2006 06:34  |
Ken Mankoff
Messages: 158 Registered: February 2000
|
Senior Member |
|
|
On Wed, 22 Mar 2006 kl_tah@hotmail.com wrote:
> Hi, does anyone happen to know how to extract a sequence of
> numbers (including the sign) between two characters? for eg. I
> have
>
> AAAA = -23.445 /BBBBB
> and could like to extract the number between '=' and '/'
IDL> print, stregex(string, "[0-9.\-]+", /subexpr, /extract)
works in the example above. More generally, removing all letters
would be this:
IDL> print, stregex(string, "[^a-zA-Z]+", /subexpr, /extract)
But you get the = and the trailing "/".
IDL> print, stregex(string, "[^\ \=a-zA-Z\/]+", /subexpr, /extract)
removes all spaces, equals, letters, and / characters...
-k.
|
|
|
Re: extracting numbers [message #48033 is a reply to message #48028] |
Wed, 22 March 2006 23:43  |
Klaus Scipal
Messages: 45 Registered: November 1997
|
Member |
|
|
Try following
tmp=strsplit(string,['=/'],/extract)
number=float(tmp[1])
cheers, Klaus
<kl_tah@hotmail.com> wrote in message
news:1143089539.095096.210300@u72g2000cwu.googlegroups.com.. .
> Hi, does anyone happen to know how to extract a sequence of numbers
> (including the sign) between two characters? for eg. I have
>
> AAAA = -23.445 /BBBBB
> and could like to extract the number between '=' and '/'
>
> cheers,
>
|
|
|