From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,e2413c4fccb33dbc X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!i18g2000prf.googlegroups.com!not-for-mail From: deadlyhead Newsgroups: comp.lang.ada Subject: Re: determining input data type Date: Fri, 17 Oct 2008 23:53:54 -0700 (PDT) Organization: http://groups.google.com Message-ID: <214384a8-9f78-4797-a194-457166456462@i18g2000prf.googlegroups.com> References: NNTP-Posting-Host: 67.171.30.9 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1224312834 9494 127.0.0.1 (18 Oct 2008 06:53:54 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 18 Oct 2008 06:53:54 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: i18g2000prf.googlegroups.com; posting-host=67.171.30.9; posting-account=snJuNwoAAABnc8T9lYkBlDQrDdSjOjG2 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092816 Iceweasel/3.0.1 (Debian-3.0.1-1),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:2439 Date: 2008-10-17T23:53:54-07:00 List-Id: On Oct 17, 5:48=A0pm, jedivaughn 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 =3D> 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