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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,37c1f61bd0b7914 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!59g2000hsb.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Converting Type Characters to type string Date: Mon, 31 Mar 2008 01:54:24 -0700 (PDT) Organization: http://groups.google.com Message-ID: <2d291584-9cb9-4a3f-8626-7b7066e60566@59g2000hsb.googlegroups.com> References: <8f5967a7-17ab-4eda-80fc-5cb58ae011f5@s50g2000hsb.googlegroups.com> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1206953664 9060 127.0.0.1 (31 Mar 2008 08:54:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 31 Mar 2008 08:54:24 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 59g2000hsb.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.3) Gecko/20040924,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:20665 Date: 2008-03-31T01:54:24-07:00 List-Id: As a matter of general principle, I always use a for loop when traversing an array: procedure Get_Digits (Result : out String; Last : out Natural); -- Reads at most Result'Length characters from standard input. Stops -- after the first character that is not a decimal digit. -- On output, Result (Result'First .. Last) contains the digits from stdin; -- Last may be zero, indicating no digits entered (i.e. one character that -- is not a digit was read). procedure Get_Digits (Result : out String; Last : out Natural) is begin Last := Result'Last; -- be optimistic for Index in Result'Range loop Ada.Text_IO.Get (Result (Index)); if not Ada.Characters.Handling.Is_Digit (Result (Index)) then Last := Index - 1; exit; end if; end loop; end Get_Digits; procedure Test_Get is Str : String (1 .. 10); Last : Natural; begin Get_Digits (Result => Str, Last => Last); Ada.Text_IO.Put_Line (Str (1 .. Last)); end Test_Get; -- Ludovic Brenta.