comp.lang.ada
 help / color / mirror / Atom feed
From: "SteveD" <nospam_steved94@attbi.com>
Subject: Re: how to check if a string variable contains a number or string?
Date: Tue, 19 Nov 2002 03:19:23 GMT
Date: 2002-11-19T03:19:23+00:00	[thread overview]
Message-ID: <%4iC9.79850$QZ.12486@sccrnsc02> (raw)
In-Reply-To: a04a773e.0211181241.4e9e13b0@posting.google.com

"Sarah Thomas" <mabes180@aol.com> wrote in message
news:a04a773e.0211181241.4e9e13b0@posting.google.com...
> 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

There are some handy string handling functions in Ada.Strings.Fixed.

To do a quick check to see if a string contains an integer number I usually
create a map (Ada.Strings.Maps) and then search for a character that is
not a digit using Index (Ada.Strings.Fixed).  If I find a non-digit
character
it's not a number.

I just noticed that Ada.Strings.Maps defines a "Character_Sequence" as a
subtype string, and there is a Is_Subset function that could be used to do
the
job as well.

Of course this only works if the "numbers" are integers.

I hope this helps,
SteveD





  parent reply	other threads:[~2002-11-19  3:19 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
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 [this message]
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