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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5c709276a96171f1 X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: newbie question: String to Integer conversion Date: 1999/12/09 Message-ID: <38503729_4@news1.prserv.net>#1/1 X-Deja-AN: 558764352 Content-transfer-encoding: 7bit References: Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: abuse@prserv.net X-Trace: 9 Dec 1999 23:11:37 GMT, 129.37.62.241 Organization: Global Network Services - Remote Access Mail & News Services Mime-version: 1.0 Newsgroups: comp.lang.ada Date: 1999-12-09T00:00:00+00:00 List-Id: In article , noam@interspective.nl (Noam Kloos) wrote: > I tried to make a program and it worked. However I also tried to use > Ada.Command_Line package. My argument must be an integer, but > Ada.Command_Line passes a String. I do not know how to convert a > string into an Integer. All scalar types (including type Integer) come with an attribute T'Value which takes a string and returns a value of the (scalar) type. See the appendix re "predefined language attributes" in your RM. Note also that T'Value accepts a string that has the syntax of a based literal, something like: I := Integer'Value ("16#ABCD#"); Occasionally I meet Ada programmers who don't know this, and proceed to write their own conversion algorithm. If this is terminal input, you don't have to require that the user specify the complete syntax; you can fill it for him: Put ("Enter hex value: "); Get_Line (Line, Last); Value := Integer'Value ("16#" & Line (1 .. Last) & "#"); This way, the user only has to enter "abcd", instead of "16#abcd#". -- Why stop at evolution and cosmology, though? Let's make sure that the schoolkids of Kansas get a really first-rate education by loosening up the teaching standards for other so-called scientific ideas that are, after all, just theories. The atomic theory, for example. The theory of relativity. Heck, the Copernican theory--do we really know that the universe doesn't revolve around the earth? John Rennie, Scientific American, Oct 1999