comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos" <david.c.hoos.sr@ada95.com>
Subject: Re: how to check if a string variable contains a number or string?
Date: Mon, 18 Nov 2002 15:50:05 -0600
Date: 2002-11-18T15:50:05-06:00	[thread overview]
Message-ID: <mailman.1037656262.18508.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: u4raetwj0.fsf@gsfc.nasa.gov


----- Original Message ----- 
From: "Stephen Leake" <stephen.a.leake.1@gsfc.nasa.gov>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Monday, November 18, 2002 3:09 PM
Subject: Re: how to check if a string variable contains a number or string?


> mabes180@aol.com (Sarah Thomas) writes:
> 
> > I have an array of strings that I read in from a file. I want to check
> > if each element in the array is a string or if it is a number. is
> > there any predefined functions that would help do that? thanks
> 
> This sounds like a homework problem. If it is, please say so. We don't
> do homework for you, but we can give advice.
> 
> Since you are reading strings, obviously what you got is a string.
> It's possible that the string contains a valid number; I guess that is
> what you want to check.
> 
> Try reading the number from the string using Ada.Text_IO.*
It's cheaper and easier to use, say, Long_Float'Value, since 'Value for
real types will accept strings with or without a decimal point.

The downside is that Ada will disregard underscores embedded in
strings when attempting to convert a string to a numeric value.

If that's OK, then if calling Long_Float'Value doesn't raise
Constraint_Error, then the string is a valid decimal representation of a
number.

> 
> -- 
> -- Stephe
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
> 




  reply	other threads:[~2002-11-18 21:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-18 20:41 how to check if a string variable contains a number or string? Sarah Thomas
2002-11-18 21:09 ` Stephen Leake
2002-11-18 21:50   ` David C. Hoos [this message]
2002-11-19  0:44 ` sk
2002-11-19  1:21   ` Jeffrey Carter
2002-11-19  4:41     ` sk
2002-11-19 17:02       ` Jeffrey Carter
2002-11-24  0:10         ` AG
2002-11-23 20:05           ` Jeffrey Carter
2002-11-19  1:26 ` Jeffrey Carter
2002-11-19  3:19 ` SteveD
2002-11-19  9:38 ` Preben Randhol
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox