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

Home » Public Forums » archive » Re: converting strings into numerical or string data depending on the contents
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: converting strings into numerical or string data depending on the contents [message #81581] Tue, 02 October 2012 16:26
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Tuesday, October 2, 2012 7:09:23 PM UTC-4, M. Katz wrote:
> I'm looking for a way to elegantly transform string values:
>
> (a) keeping it as string-type when the string does not contain only numbers
>
> (b) convert into numeric-type data when appropriate.
>

You could look at the functions http://idlastro.gsfc.nasa.gov/ftp/pro/misc/valid_num.pro
and http://idlastro.gsfc.nasa.gov/ftp/pro/misc/strnumber.pro

The first uses stregex to identify a valid number, while the second traps a conversion error. They could be used like

if strnumber(x,value) then x = value
if valid_num(x,value) then x = value
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: converting strings into numerical or string data depending on the contents
Next Topic: Re: contour plots on map with Coyote Graphics System in postscript

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

Current Time: Wed Oct 08 19:36:30 PDT 2025

Total time taken to generate the page: 0.00309 seconds