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

Home » Public Forums » archive » Testing validity of numerical content of a string
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Testing validity of numerical content of a string [message #51744] Wed, 06 December 2006 17:29 Go to previous message
Y.T. is currently offline  Y.T.
Messages: 25
Registered: December 2004
Junior Member
Maybe this is a stupid question, but is there a way in IDL to tell
whether a string contains a valid representation of a particular data
type? For example an integer? I can do something like

test = fix(str)

which will return zero (and throw an error message) if str is, say,
"hello". But is there a way to tell whether type conversion of a string
will work if attempted?

The context is a bunch of (ascii formatted) data that's been
transmitted through various channels and could conceivably be broken on
a bit-level. So the first sanity check I'd like to perform is to test
whether the received data still "looks like a number" (and then in the
second step I'll perform a couple sanity checks on whether the number
is in a valid range and such).

I am perfectly able and willing to write my own parser that looks at
the individual aspects of the string step-by-step (is the string empty?
Is the first character a digit? etc etc) but parsing for something like
a double (that could be '-.3e-4' or such) would be a major pain.

(I tried "execute" but by itself it just throws the same errors and at
least 6.3/Win it appears that the "quiet" stuff fails:

IDL> test = execute(s)
Type conversion error: Unable to convert given STRING to Double.
Detected at: $MAIN$ 1 C:\Documents and
Settings\idl\test.pro
IDL> test = execute(s,/QuietExecution)

test = execute(s,/QuietExecution)
^
Keyword parameters not allowed in call.

Dunno. )

Anybody have something clever at hand?
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: creating MPEG in IDL
Next Topic: changing widget_button values can be very slow

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

Current Time: Thu Oct 09 20:44:42 PDT 2025

Total time taken to generate the page: 0.72030 seconds