From: tmoran@bix.com
Subject: Re: integer'image
Date: 2000/04/17
Date: 2000-04-17T00:00:00+00:00 [thread overview]
Message-ID: <CuJK4.1895$lM4.482913@news.pacbell.net> (raw)
In-Reply-To: 29IK4.5459$sB3.3596@news.indigo.ie
> integer_string:string(1..2);
> integer_string:=integer'image(x);
> everything is fine until x=10. This raises a constraint error which I
> interpret to be a problem with mismatched string lenghts. If I increase
> integer_string lenght a constraint error is raised on the first iteration.
>
> I'm sure that it is a standard application to convert integers to their
> string images but I can't figure what I'm missing here.
Integer'image(1) is " 1", a two character string.
Integer'image(10) is " 10", a three character string.
Integer'image(100) is " 100", a four character string.
so declaing the string to be 2 characters long limits you to
integer'image of -9 .. 9. The usual idiom is to do
declare
integer_string : string :=integer'image(x);
begin
...
end;
which will make integer_string just exactly the right length, not
too short and not too long.
If you need integer_string to be available more globally, try
integer_string : string(1 .. 4) := (others=> ' '); -- max " 999"
...
declare
this_integer_string : constant string := integer'image(x);
begin
integer_string
:= (this_integer_string'length+1 .. integer_string'length => ' ')
& this_integer_string;
end;
Alternatively, just use Ada.Text_IO.Integer_IO.Put
next prev parent reply other threads:[~2000-04-17 0:00 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-04-17 0:00 integer'image NANCY HEHIR
2000-04-17 0:00 ` tmoran [this message]
2000-04-17 0:00 ` integer'image Ted Dennison
2000-04-18 0:00 ` integer'image Marin D. Condic
2000-04-18 0:00 ` integer'image Ted Dennison
2000-04-18 0:00 ` integer'image Marin D. Condic
2000-04-19 0:00 ` integer'image MaggieJohn
-- strict thread matches above, loose matches on Subject: below --
1991-01-28 3:27 integer'image Jim West (Stealth Contractor)
1991-01-28 15:04 ` integer'image Michael Feldman
1991-01-28 23:09 ` integer'image (George C. Harrison) Norfolk State University
1991-01-29 19:55 ` integer'image stephen edwards
[not found] <2563@sparko.gwu.edu>
1991-01-18 19:13 ` integer'image Arthur Evans
1991-01-18 20:32 ` integer'image Michael Feldman
1991-01-20 2:54 ` integer'image Hoysch
1991-01-20 23:10 ` integer'image Michael Feldman
1991-01-21 15:23 ` integer'image Jerry Callen
1991-01-21 19:41 ` integer'image Steven V. Case
1991-01-21 21:54 ` integer'image Jerry Callen
1991-01-22 19:21 ` integer'image Michael Feldman
1991-01-22 21:37 ` integer'image Richard Pattis
1991-01-23 16:29 ` integer'image Michael Feldman
1991-01-18 23:05 ` integer'image (George C. Harrison) Norfolk State University
1991-01-19 10:51 ` integer'image Jean Pierre Rosen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox