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.5 required=5.0 tests=BAYES_00,INVALID_MSGID, PP_MIME_FAKE_ASCII_TEXT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII X-Google-Thread: 103376,2593fb5bab2d7de1 X-Google-Attributes: gid103376,public From: ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe) Subject: Re: String Segment to Integer Question Date: 1997/09/29 Message-ID: <60ndce$qce$1@goanna.cs.rmit.edu.au>#1/1 X-Deja-AN: 276333009 References: Organization: Comp Sci, RMIT University, Melbourne, Australia. NNTP-Posting-User: ok Newsgroups: comp.lang.ada Date: 1997-09-29T00:00:00+00:00 List-Id: David Conly writes: >Is there any way to take a portion of a string inputed by the user at >the keyboard and make it into an integer. The keyboard has nothing to do with it. with Ada.Text_IO, Ada.Integer_Text_IO; procedure Demo is procedure Use_Value(S: in String; H: out Integer; M: out Integer) is -- Precondition: -- S = "H" & "h" & "MN" for some digits H, M, N. -- Postcondition: -- H = "H" as an integer -- M = "MM" as an integer -- Method: -- Uses standard 'Value attribute. begin H := Integer'Value(S(1..1)); M := Integer'Value(S(3..4)); end Use_Value; procedure Use_Get(S: in String; H: out Integer; M: out Integer) is -- Interface: -- same as Use_Value -- Method: -- Uses Ada.Integer_Text_IO.Get from a string. Last: Positive; begin Ada.Integer_Text_IO.Get(S(1..1), H, Last); Ada.Integer_Text_IO.Get(S(3..4), M, Last); end Use_Get; procedure Show_Result(S: in String; H, M: in Integer) is begin Ada.Text_IO.Put('('); Ada.Integer_Text_IO.Put(H, Width => 1); Ada.Text_IO.Put(','); Ada.Integer_Text_IO.Put(M, Width => 2); Ada.Text_IO.Put(") <= '"); Ada.Text_IO.Put(S); Ada.Text_IO.Put_Line("'."); end; S: constant String := "8h32"; H, M: Integer; begin Use_Value(S, H, M); Show_Result(S, H, M); Use_Get(S, H, M); Show_Result(S, H, M); end Demo; -- John �neas Byron O'Keefe; 1921/02/04-1997-09-27; TLG,TLTA,BBTNOTL. Richard A. O'Keefe; http://www.cs.rmit.edu.au/%7Eok; RMIT Comp.Sci.