comp.lang.ada
 help / color / mirror / Atom feed
From: reason67@my-deja.com
Subject: Re: Number into String
Date: 2000/01/06
Date: 2000-01-06T00:00:00+00:00	[thread overview]
Message-ID: <852k73$4p7$1@nnrp1.deja.com> (raw)
In-Reply-To: 852dmq$vad$1@nnrp1.deja.com

In article <852dmq$vad$1@nnrp1.deja.com>,
  Robert Dewar <robert_dewar@my-deja.com> wrote:
> In article <852crn$umf$1@nnrp1.deja.com>,
>   reason67@my-deja.com wrote:
> > In article <851a0e$tp7$1@green.kreonet.re.kr>,
> >   "Jeong, Lae Hyung" <lovelace@dreamwiz.com> wrote:
> > >     I've found !!
> > >
> > >     S : String := Integer'Image(NUM);
> >
> > This thread is kinds fortunate for me to ask a question. I
> often have
> > the case where I need to put a number into a string of fixed
> length.
>
> So use the facilities in Text_IO!

Can't do that. The reason why is stated in the last line of the comment
I supplied at the beginning of my procedure:

     -- If
     -- the length of Number String is greater than the Length
     -- provided, the left most portion of the Number that can fit
     -- in the result is returned.
     --

Text_IO returns a layout_error in this case.

----------
----------

with Ada.IO_Exceptions;
with Ada.Text_IO;

procedure Aaa_Test_It is

    package Int_IO is new Ada.Text_IO.Integer_IO (Integer);

    Number : Integer := 5000;
    Str1   : String (1 .. 3);
begin
    Int_IO.Put (To   => Str1,
                Item => Number);

    Ada.Text_IO.Put_Line (Str1);
exception
    when Ada.IO_Exceptions.Layout_Error =>
        Ada.Text_IO.Put_Line ("Str1 will not work");
end Aaa_Test_It;


I could do the text_io on a larger string than is required and then copy
it into the smaller string, but that is essentially the same thing as I
am doing with the 'image so it does not gain me anything.
---
Jeffrey Blatt



Sent via Deja.com http://www.deja.com/
Before you buy.




  reply	other threads:[~2000-01-06  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-06  0:00 Number into String Jeong, Lae Hyung
2000-01-06  0:00 ` Richard D Riehle
2000-01-06  0:00 ` Jeong, Lae Hyung
2000-01-06  0:00   ` reason67
2000-01-06  0:00     ` Robert Dewar
2000-01-06  0:00       ` reason67 [this message]
2000-01-06  0:00         ` James S. Rogers
2000-01-06  0:00   ` Robert Dewar
2000-01-06  0:00 ` Jeong, Lae Hyung
2000-01-06  0:00   ` Robert A Duff
2000-01-06  0:00 ` David C. Hoos, Sr.
  -- strict thread matches above, loose matches on Subject: below --
2000-01-06  0:00 mfeldman
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox