From: deadlyhead <deadlyhead@gmail.com>
Subject: Re: determining input data type
Date: Fri, 17 Oct 2008 23:53:54 -0700 (PDT)
Date: 2008-10-17T23:53:54-07:00 [thread overview]
Message-ID: <214384a8-9f78-4797-a194-457166456462@i18g2000prf.googlegroups.com> (raw)
In-Reply-To: d39e1918-0c74-40b5-860d-f8d93181afd2@p59g2000hsd.googlegroups.com
On Oct 17, 5:48 pm, jedivaughn <jedivaugh...@gmail.com> wrote:
> Hi, How is the best way to determine the type of input. I have the
> input coming in through a string but if the contents of the string is
> an integer then I want to convert it to such. This seems like it
> should be very easy to do but I can't seem to find out how to do it
> any where.
>
> Thanks,
>
> John
Exceptions are a wonderful thing:
-- file: int_test.adb
-- Tests to see if an input string is an integer
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Int_Test is
My_Int : Integer;
begin
Put("Give me some input, and I will tell you if it is an integer:
");
Get(My_Int);
Put(My_Int, 0);
Put(" is an integer!");
New_Line;
exception
when Data_Error =>
Put("That was not an integer!");
New_Line;
end Int_Test;
Using Ada.Integer_Text_IO.Get does some work for you, though. For
instance, if the user inputs 214yy0, it puts 214 in My_Int and
continues on its way. This may not be what you want, thus some actual
text processing may be in order.
-- deadlyhead
next prev parent reply other threads:[~2008-10-18 6:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-18 0:48 determining input data type jedivaughn
2008-10-18 1:41 ` Jeffrey R. Carter
2008-10-18 6:17 ` Paul
2008-10-18 6:53 ` deadlyhead [this message]
2008-10-18 8:00 ` Dmitry A. Kazakov
2008-10-18 18:54 ` anon
2008-10-20 11:01 ` jedivaughn
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox