From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Converting Type Characters to type string
Date: Mon, 31 Mar 2008 01:54:24 -0700 (PDT)
Date: 2008-03-31T01:54:24-07:00 [thread overview]
Message-ID: <2d291584-9cb9-4a3f-8626-7b7066e60566@59g2000hsb.googlegroups.com> (raw)
In-Reply-To: leCdnR19L-5M_G3anZ2dnUVZ_j-dnZ2d@comcast.com
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.
next prev parent reply other threads:[~2008-03-31 8:54 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-30 20:04 Converting Type Characters to type string jedivaughn
2008-03-30 20:19 ` Pascal Obry
2008-03-30 21:08 ` jedivaughn
2008-03-30 21:28 ` jimmaureenrogers
2008-03-30 21:38 ` Ludovic Brenta
2008-03-30 21:48 ` Georg Bauhaus
2008-03-30 23:52 ` jedivaughn
2008-03-31 3:04 ` george.priv
2008-03-31 4:00 ` tmoran
2008-03-31 8:54 ` Ludovic Brenta [this message]
2008-03-31 9:59 ` Dmitry A. Kazakov
2008-03-31 10:59 ` Jean-Pierre Rosen
2008-03-31 13:50 ` jedivaughn
2008-03-31 14:11 ` Ludovic Brenta
2008-03-31 14:21 ` Dmitry A. Kazakov
2008-03-31 14:44 ` jedivaughn
2008-03-31 15:41 ` Adam Beneschan
2008-03-31 20:26 ` Maciej Sobczak
2008-03-31 22:06 ` Georg Bauhaus
2008-03-31 22:33 ` Adam Beneschan
2008-04-01 1:00 ` jedivaughn
2008-04-01 5:34 ` Simon Wright
2008-04-01 11:22 ` jedivaughn
2008-04-01 12:00 ` jimmaureenrogers
2008-04-01 13:22 ` jedivaughn
2008-04-01 17:03 ` Adam Beneschan
2008-04-01 21:11 ` Simon Wright
2008-04-01 22:22 ` jedivaughn
2008-04-03 5:54 ` tmoran
2008-04-03 14:38 ` Adam Beneschan
2008-04-01 16:58 ` Adam Beneschan
2008-03-31 15:45 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox